Monday, August 7th, 2006

Book Review – Ajax Patterns and Best Practices

Category: Book Reviews, Books, Design

<p>Ajax Patterns and Best Practices (Expert's Voice)
Digg this review!
Christian Gross’ Ajax Patterns and Best Practices is a quality book for the intermediate to advanced ajax programmer who is looking to expand their skills. This is definitely not a beginner’s introduction to ajax, as once you get past the first three chapters or so Gross dives into some heavy duty patterns for difficult problems in ajax. The book suffers from a lack of editing and a few curious technical remarks, but overall it does a good job of covering ajax patterns and practices. Gross is obviously a fan of REST and XML, so your views on this book might depend upon how much you agree with his technical choices.

Chapters one and two cover the basics of the XHR object and using the factory pattern to abstract away browser differences for the object. Chapter three covers “Content Chunking”, Gross’ term for what he admits is core to ajax – an event leading to an asynchronous request with then responds with some sort of content to inject back into the document. Chapter four covers caching practices, and five covers the “permutations” pattern – ie separating the URL resource from the representation. Six covers “decoupled navigation” (ie seperating the event triggering/handling from the business logic they fire), seven covers switching between states seamlessly, and eight covers the even popular “persistent communication” (ie polling) pattern that many of you may have seen yesterday in coverage of the WWDC. Nine covers workflows in ajax with the “state navigation” pattern, ten is “infinite data” (see the scrollbar at live.com), and eleven covers treating remote services as the model in MVC via REST.

So there is a lot of content here, and the code examples are done well for the most part. The code used in the book was extracted later into a framework, so its nice to see the code being used for something beside toy examples. Server side examples are in Java or C# with a few exceptions, with all of the serialization in XML with some XLST examples also shown. The javascript code seems to follow some strange conventions, with TitleCase function names for example. There are no third party frameworks used or covered.

Regarding serialzation, Gross has this to say about XML vs everything else:

Many people might think that XML has its problems and have proposed protocols that are better. Frankly, I think that is plain wrong…Therefore, when writing your own Ajax and REST applications, stick to XML.

While I certainly see Gross’ point about the benefits of interoperability with web services when using XML, he fails to mention how sites like Yahoo and del.icio.us are offering their data in JSON. If your app will only ever talk to del.icio.us, for example, it might not be best to go with XML. There are also the cases where you have complete control over the services, for an intranet app for example, and you may go with JSON or YAML for developer friendliness. I think at least discussing serialization in the context of a simpler app that doesn’t talk to web services would have been helpful for developers who aren’t writing the next big XML mashup.

Besides that nitpick, this book will be great for someone who wants to know some of the big pitfalls of creating large scale ajax apps, and ways to sidestep them. The only other significant fault is the editing, with one too many awkward run-on-sentences. The overall tone is conversational and easy to follow once you get past that. The patterns covered are very useful, particularly the caching pattern and the different ways of handling transitioning and transforming state. Recommended, particularly if you are doing a lot work with REST/XML and multiple web services. If you can only own one Ajax book – get Ajax in Action – if you own two, make Ajax Patterns and Best Practices your second choice.

Related Content:

Posted by Rob Sanheim at 10:53 pm
3 Comments

+++--
3.7 rating from 41 votes

3 Comments »

Comments feed TrackBack URI

I’m not surprised he is saying xml is the best format for data interchange – only because it is easy to create at the back end.

However I never use xml any more, it is bloated and cannot be easily converted to JS objects. I have written a json creator in c# which makes light work of creating json

Comment by Gaz Elms — October 30, 2006

I agree with Gaz, coz of my own experience with xml that made ajax a too difficult experience for me. Now I feel more relaxed with JSON and the best part is its usage for web services from Yahoo, Google and others. So no need to go through those proxy hacks for cross server ajax.

Comment by ajaxhash — December 17, 2007

So it means that no patternes related to JSON are covered in this book? I was looking for it, but if has only clinged to xml, better I stop now.

Comment by softwareoutsouring — December 17, 2007

Leave a comment

You must be logged in to post a comment.