One year ago, Thomas Lackner didn’t ask much of JavaScript. When he sketched out the architecture to a Web application, he
knew he could count on the browser language for “set-a-cookie hacks” and for loading images, but he turned to the server side
for the heavy lifting. But when Google began launching highly interactive Web sites such as Gmail and Google Suggest, the
scales dropped from Lackner’s eyes and he saw the opportunity.
“It all clicked in my head the middle of 2004,” Lackner says. “I started trying to add AJAX components to every Web app I
worked on.”
AJAX is the newly minted acronym encompassing a fresh vision of empowered browsers: Asynchronous JavaScript and XML. Before
AJAX, Web pages displayed links, forms, and buttons. When a user clicked on a link or a button, the browser sent a message
to a distant server asking what to display next. JavaScript would typically be used for nothing more than to check form inputs.
Web pages were as static as pages in a book.
The post-AJAX browser can think on its own without saying “Mother may I?” to a distant server. Processing threads running
in the background preloads page content. If a user clicks on a link or a button, the browser can update page content using
JavaScript. Google’s Gmail, for instance, hides or displays parts of an e-mail thread without waiting for a response from
its server, eliminating network lag. If information must go to the server, it too is sent by a background process.
Brendan Eich, the creator of JavaScript at Netscape, says the world is just now discovering what he imagined back in 1995.
He says, “We [Marc Andreessen and I] always intended JavaScript to enable client-centric apps that did not have to reload
pages from a server.”
A new kind of app
AdaptivePath’s Jesse James Garrett, who coined the AJAX acronym in an essay written in February, says that the response has
been surprising. “Right now, it’s all so new that what we’ve got is a lot of excitement,” he says.
The excitement is understandable when you consider the advantages AJAX brings. For one thing, it greatly simplifies software
distribution. Browsers load AJAX applications automatically. Customers are often reluctant to install custom applications,
but most people can be convinced to visit a Web site.
The AJAX approach has several other advantages, as well. JavaScript running on the client reduces bandwidth and processing
demands on the server. Well-designed code that is truly asynchronous also gives the server more time to respond to queries,
reducing this load even further by spreading out peak demands. It even increases security by encrypting data on the client
side, before it travels across the network.
The Basecamp project-management application from 37signals is a good example of a Web application developed using the new
paradigm. Adding a new to-do item pops open a window to accept input without a round-trip to the server. But when the new
item is saved, the browser still must wait to ensure that it was stored successfully. JavaScript code updates the server in
the background while displaying the note, “Moving ... Just a moment.” There is still plenty of interaction with the server,
but the JavaScript code speeds it by handling many of a user’s clicks.
David Heinemeier Hansson, a programmer at 37signals, says he’s concentrating on removing the lag time when a user submits
a form. “If you have a Weblog and you add a comment, it will be updated on the server side in the background. Whenever you
need to add or change content, you can do it without reloading.”
Some of the buzz surrounding AJAX has been generated by Web designers as well as programmers. AJAX’s flexibility is invigorating
for Web designers because JavaScript can control any aspect of any images or type on a page. Fonts can grow or shrink. Tables
can add or lose lines. Colors can change. Although none of these capabilities are new to programmers accustomed to building
client applications -- or, for that matter, Java applets -- they are novelties to Web designers who would otherwise be forced
to rely on Macromedia Flash.