Relevance Review #3: Foundations of Ajax

This is a review of Foundations of Ajax, from Apress. Full disclosure: I have met, and really liked, Nathaniel Schutta, not least of which reason is he quotes me.

Quick summary: Chapters 5-7 worth the cover price. Rest of the book could be shortened, and replaced with more of chapters 5-7.

The Foundation series from Apress seeks to give readers the fundamentals of a given technology. This book delivers very literally on that premise; perhaps too literally. The authors give the readers a long treatise on writing Ajax code using raw JavaScript while ignoring all of the higher-leverage frameworks that are typically employed. While instructive, it leaves the book feeling somewhat less than practical.

Chapter 1 is a history of the Universe through the lens of distributed programming. As a person who has tried to deliver that story in front of a live audience, I can readily attest that such a history is often lacking in detail and perceived as redundant by the audience. This chapter suffers from those problems, and while interesting, would have been better as a prolog than a whole chapter.

Chapters 2 and 3 introduce and explain the usage of XMLHttpRequest. These chapters are both the central premise of the book, and its greatest weakness. The authors explain in detail the vanilla JavaScript required to invoke the XHR object, to interact with the request/response streams, and to navigate the DOM (of both the web page and the response data). This is where the authors choose not to discuss the Ajax frameworks that can help you with the boilerplate code, and instead focus on rolling your own. And we really like for folks to understand the inner workings of a technology, so I say 10 out of 10 for effort. The balance of code and explanation is also spot on, with just enough of each to keep the reader interested.

However, there are some problems. The code presented in these chapters is brittle. The authors gloss over some rather important complexities. I'd give them a pass if they were then introducing frameworks that took care of the complexities for you; but since they don't, it would have been nice for the code to go into more detail. Examples are ignoring the MSXML version of XHR when showing cross-platform invocation, failing to account for multiple concurrent asynchronous requests, and robust error handling. In the last case, the authors show how to inspect the status code of the XHR response, but don't examine issues like request timeouts and corrupt data.

Chapter 4 really starts to pick up. This chapter introduces a ton of Ajax techniques in code format. It shows, in detail, how to implement your own Ajax effects like auto-complete fields, page polling, interacting with web services, and many more. The code is useful, but perhaps more useful is the effect of seeing so many techniques laid out for you, expanding your idea of what is possible in your web application. Very well done.

Chapters 5-7 should be mandatory reading for every Ajax programmer. These chapters lay out the toolkit of the series Ajax developer, introducing and explaining the uses of tools like: JSDoc, for code documentation, JSLint for error checking, JSUnit for testing, Venkman and the Microsoft Script Debugger for stepwise debugging, and a slew of tools for helping verify your XHTML/DOM/CSS. These chapters show how to treat JavaScript with respect and act as though it is a real programming language, which is exactly what it is.

In all, I think the book's code focuses too much on plain JavaScript to be really useful for a working developer, and if the code-focused chapters had been condensed to a single chapter to make more room for extra details about the toolset introduced in 5-7, the book would be much stronger. However, it probably wouldn't have been a good fit for the Foundation series, then, so it is hard to fault the authors. Recommendation: get the book, read the first half, and live the second half.

Get In Touch