Book Review: Ajax: The Definitive Guide ByLynn Greiner 2008-07-09
Article Rating: / 2
Rate This Article:
Add This Article To:
Ajax: The Definitive Guide, by Anthony T. Holdener III. O'Reilly Media Inc. 2008. $49.99. ISBN: 978-0-596-52838-6. Purchase includes 45 days of access to the Safari digital version of the title.
The static Web page is dead (or at least, like Python's parrot, resting). Web 2.0 is where it's at. And one driver for Web 2.0 is Ajax.
Ajax, for the few uninitiated, is a melding of a bunch of familiar technologies to create a greater whole. According to Jesse James Garrett, the person who coined the term, it's shorthand for Asynchronous JavaScript and XML, and, says Garrett, encompasses standards-based presentation using XHTML and CSS, dynamic display and interaction using the Document Object Model, data interchange and manipulation using XML and XSLT, asynchronous data retrieval using XMLHttpRequest, and JavaScript binding everything together. His original paper describing the concept can be found here: http://www.adaptivepath.com/ideas/essays/archives/000385.php. Ajax helps you build browser-based applications with functionality that resembles that of installed desktop apps.
ADVERTISEMENT
Why bother? Because those apps are more responsive than traditional Web apps, where every mouse click means a chat with the server running the site. That back-and-forth of tradiational apps often makes them appear sluggish, and limits what they could do.
Ajax, however, only refreshes necessary bits of a page. On MapQuest, for example, if you zoom in, only the map will change.
But this cleverness can cause issues for developers. For example, it breaks things we take for granted, such as the browser back button, and needs some modification in the way apps are built.
Author and Web developer Anthony Holdener has assembled over 900 pages of information and techniques in Ajax: The Definitive Guide. And yes, it really does need 900 pages – or maybe even more. Hacking together a Web site is easy. Developing a usable, efficient and high-performance Web site is a considerably less trivial task.
The book is broken into five parts. The first describes Ajax, explains the technologies behind it and shows how it has changed the Web. Part II is a tutorial on the use of the technologies in Ajax, and Part III builds on the techniques to help developers integrate Ajax into applications. Part IV offers some best practices in application structure and optimization, and Part V is a set of appendices.
Holdener begins by talking about the standards behind Ajax, varying in vintage from 1999's XSLT to the comparatively shiny-new 2004 XML and DOM Level 3, even including a table showing which are supported by each of the layout engines driving popular browsers. He also explains why standards compliance matters to developers. He argues that forward compatibility is more important than backward compatibility in the grand scheme of things, noting, "It is time to give users of the older browsers reasons to upgrade to something new, because let's face it, if they haven't upgraded by now (we are talking about almost a decade here), they are never going to unless they are pushed to do so. It is time to give old browser users that push, and to give users of the current browsers the sites they deserve to have."
Heresy? Perhaps to some. But you can't do Web 2.0 development without the more modern technologies – or without proper application development methodologies. That's what Chapter 2 is all about. But, Holdener cautions, Ajax is not the be-all and end-all solution to every Web development challenge. Appendix D is devoted to risks and issues created by the technology – before you get too carried away with concept, it's a must-read.
Chapter 3 takes a stroll to the server side, looking at the languages, frameworks and databases that power your apps. Covering everything from ASP.NET to Ruby on Rails, it discusses the strengths and weaknesses of each, providing code snippets to show them off.
The next couple of chapters cover scripting with XML and JSON, and take a peek inside the DOM. Holdener thinks that manipulating the DOM is the secret sauce that makes Ajax magic happen, and he gives us a ton of reference material and code snippets to illustrate that belief.
The final chapter in section one should be engraved in every developer's heart – it talks about usability. Says Holdener, "It is always good to learn from your mistakes, but a better lesson is to learn from the mistakes of others and not repeat them." He then supplies example of both good and bad design, and explains each, even getting into unexpected (but important) concepts like the golden ratio, which describes the mathematical proportions in composition that are most pleasing to the eye.
Part II gets into the technologies used in Ajax apps – site navigation, tables, lists, animation, forms, and, probably most important, data validation and error handling. This is the nuts and bolts section, with lots of code examples for everything from displaying buttons in their clicked and unclicked states to pagination. Holdener notes that many of the examples don't work in Internet Explorer (which doesn't properly support CSS2), and provides workarounds that do work. He also touches on Ajax's problems with the back button and with bookmarks.
Part III shows how the technologies described in the first couple of sections can be combined to make functioning apps. Searches, and APIs for public Web services such as blogs, maps, music and video and photo services are described. Holdener provides links to the API documentation as well as code examples.
He then gets into mashups – not only how to create them, but why NOT to do so.
Chat, file sharing and whiteboards are next, followed by a long chapter on coding a game.
The final section deals with modular coding and optimization, including remarks on packet size and its effect on performance. Holdener also spends a moment on good and bad SQL queries (Hint – avoid the UNION keyword).
The appendices give you an XML/XSLT tutorial, a quick look at JavaScript framework, toolkits and library references, a catalog of Web services and a description of the risks and gotchas in Ajax to help you decide if it's right for your application.
And then there's a 32 page index. Whew!
Despite its size, this is a readable book, although it's short on screen shots illustrating the results of the massive number of code segments in the text (which, incidentally, can be downloaded from the O'Reilly site at http://examples.oreilly.com/9780596528386/). Mind you, add many more pages and you'd need a crane to lift the thing – this is a substantial volume!
Holdener doesn't just play code jockey – he gets into topics that are critical to the real world Web developer, such as performance, security, and usability. And, perhaps most importantly, he not only talks about when to use Ajax, he shows you how to tell when it's the wrong solution.