Tom's Blog
Ajax Architecture with Stuart Halloway
Published by Tom |
November 04, 2006 07:51 AM EST |
When should you use Ajax?
Whenever you want to create a rich client application with the universal reach of the Internet.
Stuart Halloway,
speaking Friday afternoon at this fall's
Northern Virginia Software Symposium,
predicts Ajax will be part of nearly all web applications within the next year.
Stuart's first session of the day focused on the architectural issues involving Ajax,
from technical features to selling Ajax to management.
In 90 minutes he discussed:
- the reasons to use Ajax
- how to introduce Ajax at your company
- the resistance you'll encounter when you do
- the tools and libraries to use in Ajax development
- the architectural decisions you'll need to make
- how Ajax isn't a panacea for all applications
The interest in Ajax has been increasing over the last couple of years not because of a breakthrough in technology, Stuart said, but because of a breakthrough in how we look at using asynchronous JavaScript to make web forms more dynamic. Instead of having web user-interface developers deal with the vagaries of the different browser versions, different implementations of JavaScript, different implementations of Cascading Style Sheets, and different implementations of the web page document object model, they learned in February 2005 from

Jesse James Garrett
The reason to use Ajax in your web applications is to create a better experience for your users. Ajax allows your web page to communicate to the server in order to update the page "behind the user's back," making the application more responsive to the user's actions without having to reload the page.
The best way to introduce Ajax at your company, he said, is in non-core web applications. Depending on your company's culture, Stuart said, you can sell Ajax either as proven technology -- XML, HTTP requests, and JavaScript -- or by saying "Ajax is the revolution and we're all on board." When introducing Ajax, he said, stay "degradable." That is, ensure your web application still works if the user turns off JavaScript or uses a browser that doesn't support it. The fewer negative issues you create, the more the benefits will shine through and convince others to introduce Ajax into more web applications. If you want to be conservative, he said, wait until the web MVC frameworks, like JavaServer Faces, provide better support for Ajax in their page widgets.
Stuart mentioned several open source development tools and JavaScript libraries to use in your Ajax applications:
- Firefox
Consider the Firefox browser (with its extensions that follow) your development platform and Internet Explorer as your deployment platform, Stuart said. -
JavaScript Shell
a Firefox bookmarklet that allows you to dynamically run JavaScript statements against your current page in a debugging window. This tool is useful, Stuart said, "for poking around the page to figure out what's broken." -
FireBug
a Firefox add-on with debugging features to monitor your page's JavaScript, CSS, and HTML. One feature allows you to spy on all HTTP traffic JavaScript functions send to the server. -
Web Developer
a Firefox add-on toolbar that allows you to disable JavaScript, cookies, view and modify a page's CSS, view a page's generated source rather than the HTML originally loaded, and a host of other useful development tools. -
Tamper Data
a Firefox add-on that logs all web navigation. It not only allows you to see what requests and responses are traveling between the Ajax components and the server, but it allows you to modify them or completely stop the request and see how the application reacts.
Stuart mentioned several Ajax libraries. Since JavaScript libraries generally don't trample on each other, he said, you can often use more than one in a web application.
-
Prototype
A survey at an Ajaxian conference showed that more than half of the Ajax developers were using Prototype, Stuart said. Most of the rest were using Scriptaculous (next). Prototype allows you to register multiple event handlers to events (Event.observe()). You can register events outside of the HTML widget to allow you to separate concerns: your HTML page designer doesn't have to worry about coding the JavaScript events. Prototype also provides theAjax.Requestfunction that works as a factory to return the appropriate function that works with the user's browser version. -
Scriptaculous
A library built on Prototype to provide page effects (highlight, fade), drag and drop, auto-complete and other features. -
Dojo
This is a heavy-weight "kitchen sink" library, Stuart said, that provides almost everything you need for an Ajax application. -
Google Web Toolkit
This toolkit allows Java developers to build front-end components in Java. The toolkit converts the Java code to JavaScript and HTML. -
Direct Web Remoting
Stuart said DWR is No. 3 in popularity, behind Prototype and Scriptaculous. It's Java RMI like. You write JavaScript stubs that run in the browser and make RMI calls to the server. It assumes you have Java running on the server side.
- What to send on the wire?
When JavaScript calls to the server for updated information, does the server send back HTML, XML, JavaScript, or JSON? HTML is view centric, JavaScript is code-centric, and XML and JSON are model-centric. (See also this blog for a discussion.)
Stuart said he believes 95% of all Ajax traffic soon will be HTML. It's developer-efficient (no parsing and XML creation) and the snippet of HTML can simply be rendered on the page. JSON will dominate applications that focus on data exchange because it is easier to parse than XML. XML will be the loser. Sending back JavaScript allows you to send back code that the browser would evaluate.
-
What library to use?
Choose a library that supports the features you need. The library should hide the browser differences in the XMLHttpRequest. Prototype does this and builds upon JavaScript to make it more like a regular programming language.
Use Scriptaculous if you need to adds page effects and you'd like to use its widgets.
Dojo is the library beloved by Java programmers, Stuart said. It's bigger than all the other libraries, but it does more. Its API provides fixes for Back-button issues, client-side data storage, and other features.
Stuart dislikes Google Web Toolkit. "I think it's architecturally wrong," he said, but I think I zoned out when he described the reasons for his dislike.
Saturday November 04, 2006 Permalink
Comments:


