Foundations of Ajax

Nothing like a rainy afternoon to boost your reading habits... And finish long overdue pieces.

Over the last couple of weeks, as time permitted (and it was tough going where time was concerned), I've been leafing through the eBook version of Foundations of Ajax, by Ryan Asleson and Nate Schutta (who are also the co-creators of Taconite, a J2EE-oriented Ajax framework).

Now, you know all about Ajax, of course. It's that newfangled Web 2.0 development meme centered on using the XMLHTTPRequest object to dynamically rebuild pages piecemeal. But if you want to get a well-rounded view, this book might be a nice way to dive in.

Besides attention to detail and copious examples, the book delivers a nice mix of background information (i.e., besides the "hows", you also get the "whys") and a relatively language-agnostic approach - although the authors present many server-side examples written in , the emphasis is on discussing the server-side logic - to the extent of just presenting the server output alone in some cases.

Huh? ?

Now, I'm not a enthusiast (quite the contrary, I'm afraid), but truth be told that the server-side code for the examples presented makes very clear reading, and the examples are simple and short enough to avoid the risk of offending partisans from any specific language camp.

Besides addressing the basics of using XML to pack data exchanged between browser and server, there's also a no-frills, crisp and clear introduction to the benefits of using JSON for the same purpose (a technique I find much more effective and appealing for simple data structures). But, best of all, the detail extends to covering response headers (something most Ajax frameworks seem to ignore, and that I've always found a terribly useful way of exchanging information).

Although the authors introduce Taconite near the end of the book, none of this is done using it. All the examples use plain, non-abstracted JavaScript that demonstrates the basics of implementing staple techniques (filling list boxes, updating progress indicators, creating floating tooltips, autocomplete, etc.).

The White Glove Test

To round those off, the book devotes a few sections to development and testing aids (JSDoc, JSLint, JsUnit, miscellaneous XUL extensions, etc.) before diving into the infamous prototype property and the nuts and bolts of the JavaScript class/slots/inheritance mechanism (a major boon for one such as myself, who had always shied away from that rather fuzzy topic) and, later on, providing the basics for cross-browser JavaScript development.

In fact, there is a lot of emphasis on testing and debugging (more than two chapters' worth). Being one of those people who loathe JavaScript largely due to the difficulty of seeing what the code is doing behind the scenes (as opposed to just looking at the pretty effects), I appreciated that tremendously. I know many a seasoned web developer that has shied away from JavaScript and moved as much logic as possible to the server side due to the language's amazing flakiness, and these sections go a long way towards reassuring those people.

Dashing Towards The End

The pieces start adding up when you reach the final chapter, which details an Ajax implementation of a web-based (the and JavaScript sources are available for download), where each individual "widget" is dissected with care. It is all implemented with Taconite, but its lightweight nature lets you understand the details without relying too much on the framework.

Now, this may put off the kind of reader that just wants to, say, get up to speed on Rails or Django, but given the book's focus on teaching the basic techniques (which are valid no matter what you'll end up using), I think that it's more than enough for die-hard programmers who want to understand the underlying mechanics before getting mired in abstraction.

After all, the major stumbling block of taking up popular Ajax/JavaScript libraries is that you have to learn their peculiarities and approaches, and it's all a lot easier if you know how things are supposed to work underneath the hood.


Like the few other Apress books I've been exposed to, Foundations of Ajax, becomes "sticky" due to its balanced approach - it's something you read instead of just dipping in and picking up quick recipes to scratch whatever itch you may have, and the smooth ramping in complexity as techniques unfold makes for a good learning experience.

If you want to use Ajax but aren't yet ready to commit to a specific framework, this might be the book to get you started.