Picture of jgehtland

Relevance Review #3: Foundations of Ajax

  • Posted By Justin Gehtland on April 10, 2006

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.

Comments
  1. Raymond BriglebApril 12, 2006 @ 10:06 AM
    I agree very much with your conclusions about this book. It's a bit bare-bones, there's little or no coverage of the frameworks you'll actually be using most of the time. Good fundamentals though. However, for my money, I found Manning's Ajax In Action to be brilliant, amazingly good for how quick it was to market. Great book. Hope you get a chance to review that one too. Of course, the Pragmatic Ajax beta book is brilliant, too!
  2. JustinApril 12, 2006 @ 10:09 AM
    Ajax in Action is on the list, trust us.
  3. Nate SchuttaApril 12, 2006 @ 07:28 PM
    Justin, Thanks for the writeup, Ryan and I appreciate your thoughts. BTW, feelings mutual! I really enjoyed chatting with you at NF and I wish I had been able to join you guys at dinner... Couple of points. First, when we wrote Foundations, the library space was just getting started and we figured (rightly) that anything we would have written about last May/June/July would be out of date today. If we get a chance to do a second edition we would obviously include a writeup on Prototype, Dojo, etc (in fact we're working on another book - Pro Ajax and Java - that covers the major libraries). Second, thanks for noticing the tools chapters! Ryan and I were really trying to help developers by showing them what's available now to ease the pain of JavaScript. Lastly, I know what you mean about chapter 1...we were trying to set the table and answer the proverbial "why now" question that seems to float around the Ajax space. Anyway, thanks again, hopefully I'll have a chance to catch up with you at RailsConf!
  4. JustinApril 12, 2006 @ 07:40 PM
    Nate -- I figured the library coverage was something like that, but I didn't get a chance to ask about it at NFJS. And, like I said, I've tried to tell that Chap 1 story a bunch of times, and for the same reasons, so I know the problems. Looking forward to Proj Ajax and Java -- we'll review that one too! ;-)
  5. BartApril 13, 2006 @ 08:54 AM
    I found the Foundations of Ajax to be a good primer on the ideas behind how it works. It seems to be more targeted at you IT management type of audience (people who understand code, but don't do much of it anymore). It is enough to say "here is what you can do" without giving the dirty details. For someone who is down in the trenches, there are some nice tips and tricks, but most of it is going to be things that are already known. All in all, I would say get this book for your boss so that you can talk to him about what you are coding without getting a blank stare back.
  6. Nate SchuttaApril 13, 2006 @ 08:55 AM
    Well, I can echo your comments from an earlier post about the difficulty in writing about emerging technology...heck, since I wrote the Prototype/Dojo/Scriptaculous chapter, Yahoo has released their library (which I'll add) and all three have been upgraded! While that shouldn't impact my code, I want to make sure that we cover all the key aspects...and considering we've got a few more months until it's scheduled to be out I fear more change. Such is the glamorous life of a tech writer! BTW, if you email your contact info I'll make sure you get a review copy (happy to forgo the $1.50 or whatever we get per copy for your assessment).
  7. Panhandle Brute Welfare SocietyMay 01, 2006 @ 12:50 AM
    Very clear :)
  8. HARI SSMay 03, 2006 @ 07:48 AM
    I WANT TO KNOW ABOUT AJAX FULLY.BECAUSE I AM GOING TO MY PROJECT IN AJAX WITH XML
  9. ajith_8000@yahoo.co.inMay 03, 2006 @ 07:50 AM
    SO PLEASE GIVE FULL REVIEW OR BOOK ABOUT AJAX
  10. Possess You Ever Been MellowMay 04, 2006 @ 07:10 PM
    Well at last catched the problem :(
  11. Vintage Motoring PosterMay 06, 2006 @ 06:50 AM
    Well done, nice instructions.
  12. Fundamentals Of Financial Management BrighamMay 06, 2006 @ 06:02 PM
    Well at last catched the problem :(
  13. Sliding Riddle DoorMay 07, 2006 @ 05:45 PM
    Just thought I'd make a note about a problem :(
  14. Turismo OaxacaMay 08, 2006 @ 12:13 AM
    That is strange...
  15. Dj Tiesto PictureMay 08, 2006 @ 12:27 PM
    Gonna have to give it a try :(
  16. Virginia Phone BookMay 09, 2006 @ 09:16 PM
    I was very dissapointed of this...
  17. Renting LeaseMay 09, 2006 @ 09:28 PM
    I had and the fix I found!
  18. Body Drench Tanning LotionMay 11, 2006 @ 03:46 PM
    The problem is my browser!
  19. Cartolina Elettroniche Laurea EsameMay 12, 2006 @ 05:40 PM
    Gonna have to give it a try!
  20. Avita Tretinoin CreamMay 14, 2006 @ 03:50 AM
    Very nice write up :)
  21. Offerta Regali ParmaMay 15, 2006 @ 06:28 AM
    The content of your show is great, I really enjoy it.
  22. How To Dial France From Uk PhoneMay 16, 2006 @ 12:53 AM
    Well at last catched the problem :)
  23. Thanks. Updated appropriately...
  24. Vasco Rossi Mp3May 17, 2006 @ 04:56 AM
    But I'm not sure why.