From Ajax Patterns
Note: The markup here is different to most patterns as it was edited directly from an HTML version.
Ajax, Balanced, Client-SOA, DHTML, Fast, Fat, Interactive, Platform, RichInternetApplication, Rich, Thick, Web2.0, WebApp
|<img style="display:none;" src="Images/inablink_067.png" height="259">|
Pam's begun entering staff appraisals into a new Ajax App. She's pleased to see the data entry is much faster: fields are validated as soon as they're filled out, searches are integrated into the form rather than in annoying popups, and the remaining form fields keep mutating to reflect what she's entered so far.
See the first chapter, <a href="ch01.html" title="Chapter 1. ">Chapter 1, </a>, for more details on the forces driving Ajax.
Users like working and playing in the browser and are now more willing to keep their data online, but are nonetheless frustrated with conventional "click'n'wait" interfaces.
Companies like web apps running on their intranets because it makes deployment much easier, but continue to be burned by unusable web apps that don't deliver the same value as a comparable desktop app.
Developers are now well-versed in the basic patterns of web architecture, and ready to take on new challenges.
Technology has opened up new opportunities for the web: broadband and beyond is becoming ubiquitous in many countries; servers can process huge quantities of requests per second; storage is growing to the point where it's feasible for individuals to host most of their personal data online.
Produce an Ajax App - a rich application capable of running inside any modern web browser. The user fires up an Ajax App by typing in a URL, clicking a link, or activating a bookmark. The Ajax App is then downloaded into the browser and the user can begin working with it immediately.
Ajax is fundamentally a user-centered pattern. As mentioned in the first chapter, the major force driving Ajax is the needs of users and their organizations to get more out of the web. For too long, people have endured pages that take forever to load, widgets that make no sense, forms that conveniently "forget" their data when they take too long to fill out. There are good reasons for people to continue using a browser, as noted in <a href="ch01.html" title="Chapter 1. ">Chapter 1, </a>, but it's in the interests of website owners and employers to do a better job at making that interaction productive and enjoyable.
Ajax aims to improve user experience within the constraint of respecting browser standards. Standard-based design obviously has the benefit of portability, but also has a usability component in itself; users interact with hundreds of websites, and appreciate consistency, a quality that quickly erodes when you rely on plugins, browser-specific features, and "creative" design ideas. Sure, incorporate a novel widget or a funky layout when it works, but for most things, the standard ways works best.
Non-standard technologies also break consistency; one reason <a href="http://flickr.com" target="_top">Flickr began migrating from Flash to Ajax</a> was because <a href="http://www.ajaxian.com/archives/2005/05/ajax_summit_eri.html" target="_top">users want to right-click to save images</a>, a standard broken by Flash. Again, don't be afraid to use a technology like Flash to achieve something standard browsers won't do - that's the whole idea behind the <a href="ch01s12.html" title="Richer Plugin">“Richer Plugin”</a> pattern. Some people will say it's not an Ajax App if it uses Flash, but the definition here would include a mostly-Ajax App that delegates to Flash (or other plugins) to fulfill some specialised task. In any event, the definition really isn't worth arguing about (after all, you can define "Ajax" however you like); the important thing is to ask what helps users - sometimes, it's better to incorporate some Flash or Java, other times a desktop solution really is the best approach.
There are two archetypal architectures for Ajax, and all applications lie somewhere along the spectrum between these extremities:
- Ajax Deluxe
Ajax Deluxe uses Ajax to the max: applications feel similar to a desktop in that the browser is driving the interaction - it mediates all interaction between the user and server, so there are no - or few - direct page refreshes. Similarly, there's no need for session tracking in the server, because in the absence of page refreshes, all relevant state can be retained inside the browser script. The server need not know about HTML at all, and might just offer generic <a href="ch01s05.html" title="Web Service">“Web Service”</a>s. An example is the Ajax calendar, <a href="http://kiko.com" target="_top">Kiko</a>.
- Ajax Lite
An Ajax Lite App feels more like a conventional web app overall, but one that's been sprinkled with Ajax here and there. For instance, Ajax might be used to validate a form before it's submitted using standard form submission, or to reveal some instructions on the page when a user requests help. An example is <a href="http://del.icio.us" target="_top">Delicious</a>, which works fine on legacy browsers, but offers Ajax <a href="ch01s41.html" title="Suggestion">“Suggestion”</a>s for the many browsers that support it.
Which will you use? The Deluxe approach suits a development team with more advanced web programming knowledge and access to relevant tools and cross-browser libraries, and will generally lead to a nicer, more effective, user-interface. It also facilitates a well-partitioned architecture, since the presentation logic can be completely isolated inside the browser and the business logic completely isolated in the server. However, Deluxe applications may place a strain on the browser and network capabilities, and might not even be possible if the browser is outdated. Ajax Lite is a better answer for older browsers, since the Ajax features can usually be "turned off" to support graceful degradation.
One of the reasons why Ajax has taken off now, in spite of people having tried similar things earlier on, is that browsers are now more consistent. For an Ajax app, you'll need to decide which browsers you're targeting and which browsers just aren't worth the effort. XMLHttpRequest is the main constraint, because it usually appeared later in a browser's feature set than other foundational technologies. Roughly, we're looking at browsers from around 2001 onwards. A <a href="http://en.wikipedia.org/wiki/Ajax_%28programming%29" target="_top">typical guideline</a> is: Internet Explorer 5+ for Windows, Firefox 1+, Mozilla 1+, Safari 1.2+, Opera 7.6+. Other browsers such as Netscape and Konqueror might be considered too. Whether you'll support all these browsers, or just a subset, depends on how important the diversity is, how much expertise or library support you have, and how much time you can devote to testing.
Building on the previous point, what happens when your application requires features not provided by the browser being used. As explained in <a href="ch01s30.html" title="Cross-Browser Component">“Cross-Browser Component”</a>, you can either check for specific features or you can check browser versions. If you do the former, you have the opportunity for graceful degradation - to cut out one specific feature, or provide a simpler alternative. It's more work, but lets you support more users. The alternative is to give up and suggest the user upgrade browser, sometimes the only thing you can reasonably do.
With Ajax Apps, there are two networking factors to consider:
- Throughput (Bandwidth)
How much data can be transferred per second?
How much time between a packet leaving the browser and arriving at the server? (Or vice-versa.)
In some cases, Ajax actually reduces throughput requirements by avoiding full page refresh. Yet, it's still important to consider, because there can still be a strain caused by patterns like <a href="ch01s21.html" title="Periodic Refresh">“Periodic Refresh”</a>, which continuously pulls down new data. When you consider that some Ajax features (e.g. <a href="ch01s42.html" title="Live Search">“Live Search”</a>) require round trips to the server on just about every keystroke, you can see why latency is becoming a growing theme in web design. For smaller packets, which are common in Ajax Apps, <a href="http://richui.blogspot.com/2005/09/ajax-reducing-latency-with-cdn.html" target="_top">latency is actually a much greater source of delay than throughput</a>, especially across long distances. Again, it comes down to benchmarking and deciding what's feasible. If a round trip takes several hundred milliseconds, responding to each keystroke will probably cause more frustration than joy.
Please refer to the examples in <a href="ch01.html" title="Chapter 1. ">Chapter 1, </a>.
Less waiting time, which makes users more productive and less frustrated.
The browser can be kept up-to-date without the user having to keep hitting refresh.
Superior widgets make input more expressive.
Visual effects and dynamic browser activity make the application feel more alive, and give users a better feeling of control.
Conventional web apps do have some advantages:
Users are more familiar with conventional apps.
Developers don't need to learn new techniques.
Compatible with older and non-standard browsers.
As the Solution pointed out, a standard web app that uses some Flash here and there can still be considered an Ajax App. Here, though, we're comparing Ajax to full-blown Flash, the kind of applications that won't do anything unless Flash is enabled.
Flash and Ajax are actually a close match. <a href="http://maps.google.com" target="_top">Google Maps</a> caused surprise when it came out, as many assumed that only Flash could produce something as rich inside the browser. Yahoo! then turned it full circle by producing a similar product, <a href="http://maps.yahoo.com/" target="_top">Yahoo! Maps</a>, in Flash. Despite the similarities, significant differences do remain. Compared to Flash, Ajax has the following benefits:
Ajax is more portable as it runs on any standard browser, although Flash support is still quite widespread.
Ajax Apps will often be more consistent, using standard web conventions familiar to most users. Flash has less established conventions, so using an app is somewhat less predictable.
Ajax works better with non-browser clients such as search engine robots.
Ajax plays nicer with browser settings such as colour preferences, and also with browser-specific features, e.g. skins, auto-completion and Greasemonkey-style enhancements.
Ajax is safer long-term as there's no lock-in to a proprietary plugin.
Due to its open nature, the community of Ajax developers is growing rapidly, so that libraries, techniques, and *cough* patterns are evolving rapidly.
Following are the benefits of Flash over Ajax. Whether these are compelling enough to write a pure Flash app depends on the circumstances; keep in mind that the most appropriate solution is often a combination of Flash and Ajax when it's not possible to stick with pure Ajax.
Flash offers richer graphics and video.
Flash allows for sound effects and playback of sound files, as well as audio input.
Rich graphical programming may be easier in Flash because, unlike Ajax, it's designed with those kind of applications in mind.
Flash allows for local storage.
For some Java developers, Ajax is deja vu. In the mid-to-late '90s, Java applets were destined to take over the browser and turn the desktop into a trivial sideshow. It didn't happen for various reasons, and Java applets are now rarely seen on the web. Still, they persist in the enterprise, and as with Flash, it's possible to combine the technologies. Some have speculated that all the interest in Ajax might breathe some life into the world of applets; it doesn't seem to be the case so far, but it's too early to be sure.
Ajax has several advantages over Java applets:
Ajax apps load in a matter of seconds, where Java applets tend to take longer because they tend to use larger libraries, and have to load them all to get started.
Ajax apps look and feel like standard web apps, while Java applets feel more like desktop apps and somewhat out of place in the browser.
Ajax features can grow organically from a conventional web app, whereas Java uses a completely different programming style that has to be written from scratch.
Java versions have changed over the years, and there are often incompatibilities between an applet and the Java environment used by the browser. Furthermore, you usually have to lag a few years behind the most recent version of Java.
Java applets have several advantages over Ajax:
Java is often used on the server-side, so there are synergies in a 100% Java solution, such as shared code and the ease with which developers can transcend tiers.
Many people know Java already, and an applet architecture means they virtually don't have to know anything at all about web technologies.
There is good support for desktop-like user-interfaces, if that's what is desired.
Sun has more recently introduced Java Web Start as a cross between the desktop and the browser. Web Start apps run off the desktop, but can be launched by activating a URL in the browser. The huge waiting times of applets are avoided because libraries can be held locally and shared across applications. It's a useful alternative to applets, more geared toward the enterprise, though it also hasn't taken off in a big way.
There has always been a decision to make between the desktop and the web. Ajax ramps up the web argument, with even mainstays of the desktop, like word processors and spreadsheets, becoming commonplace in the browser. Microsoft's "Live" strategy, which involves Ajaxified versions of its Office apps, is a major case in point. Still, other applications like games and multimedia tools won't be budging from the desktop for a long time to come.
Ajax offers the following advantages over the desktop:
An Ajax App doesn't need to be installed; it's available on any computer with a browser. Thus, it suits people who use multiple computers and people who use computers which they can't control.
Ajax data is hosted on the network, so users can access it from anywhere, and it can be backed up automatically. While this is feasible with desktop apps too, it doesn't tend to happen that way for several reasons, e.g. data migration would be difficult because there are so many different desktop versions running at the same time.
Most users are comfortable with web interaction mechanisms, and well-designed Ajax Apps exploit that familiarity.
Ajax works well with the web. Users can bookmark a "position" within an Ajax App, click on a hyperlink within the Ajax App, and so on.
Ajax Apps are upgraded with no user intervention.
Developers can choose the server-side programming and runtime environment according to their own needs, whereas desktop apps impose many constraints.
Ajax has bridged the gap, but desktop apps can still do many things that are beyond the realm of standard web browsers (See also <a href="ch01s12.html" title="Richer Plugin">“Richer Plugin”</a>):
Local file access
Sound, taking full advantage of modern sound cards.
Rich graphics, taking full advantage of modern video cards.
Keyboard shortcuts, where support is varied in the browser.
Communication to machines other than the base server, and in protocols other than HTTP.
OS-specific interaction, such as popping up alerts.
With mobile apps growing in parallel with Ajax, it's worth considering them as an alternative, albeit a less direct one. As it happens, Ajax itself may actually become a good platform for mobile apps, with <a href="http://www.opera.com/products/mobile/platform/" target="_top">Opera</a> now providing Ajax support on their mobile platform.
All of the patterns in this language relate in some way to Ajax. In particular, the Solution above points to the foundational technology patterns that really define what Ajax is all about.
 Harry Fuecks explains essentially the same distinction as <a href="http://www.sitepoint.com/blogs/2006/02/15/two-kinds-of-ajax-html-vs-client-soa/" target="_top">"Client/SOA" versus "HTTP++"</a>. Likewise, Craig Shoemaker contrasts "Ajax Applications" with "Ajax Websites".