Bulletproof Ajax

6 comments | Posted: 22 April 07 in Books, by Nathan Smith

Bulletproof Ajax The trouble with most JavaScript and Ajax related books is they make certain assumptions about the reader, namely that he or she is coming from a server-side programming background. They often say things like: “For those of you who have coded in Python…” or “Perl style regular expressions…” This is good if indeed you are familiar with Python or Perl, etc. But what about the rest of us?

Thankfully, Jeremy Keith has stepped up to fill the void with Bulletproof Ajax. This book does not presuppose a heavy programming background. Instead, it is geared towards the web designer who wants to become more of a front-end developer. The prerequisites are: understanding of semantics, HTML and CSS. If that’s you – good news! You already have a working knowledge of the Document Object Model, an essential piece of the Ajax puzzle. Who better to explain it, than co-lead of the DOM Scripting Task Force himself.

This book begins by laying the groundwork for an intelligible conversation. It defines JavaScript syntax such as: functions, methods, arrays and objects. With that vocabulary in place, it jumps into manipulating XHTML documents with JavaScript. It then explains unobtrusive concepts, and gets into the XMLHttpRequest and the world of possibilities that come with it.

This book is unique in that it actually acknowledges the drawbacks of Ajax and, like it’s namesake Bulletproof Web Design, helps you plan for contingencies. Rather than referring to accessibility as something that must be added in later, he advocates not removing it in the first place. After all, HTML is already accessible. It’s things we do to it with CSS and JavaScript that taint it. On page 102, he urges developers to:

1. Plan for Ajax from the start.
2. Implement Ajax at the end.

He also warns against using JavaScript alone to handle things like form validation and complex calculations. If you rely on this only, you have no fall-back plan. Ideally, JavaScript should be like a waiter going to a from a kitchen, serving things to the end-user. Let me share a few more quotes.

Page 99:

Far too many Ajax applications are built on the assumption that JavaScript will be available. Instead of treating the language as a tool for enhancing functionality, these applications make JavaScript a requirement. Core functionality is carried out with JavaScript, resulting in an all-or-nothing situation for the user.

Page 116:

Just because you’ve hired a waiter doesn’t mean you can fire the cook. Yet this is exactly what some Ajax applications attempt to do. Not content with having a waiter take orders and bring food, they get the waiter to do all the cooking too.

Cooking should happen in the kitchen. Application logic belongs on the server. It’s better for everyone that way. Your application will work more consistently when it’s server-based. The browser environment is simply too unpredictable.

I also appreciated Jeremy’s subtle sense of humor throughout the book: telling of the origins of the name Ajax, dating back to Greek mythology, and adding a tie-in with the name Jason when referring to JSON. If you didn’t know, he’s quite a trivia guru, especially when it comes to Star Wars Trivial Pursuit.

I applaud that Jeremy is using XHTML 1.0 Strict throughout this book, as opposed to XHTML 1.1 as in DOM Scripting. It avoids confusion over content-type: text/html vs. application/xhtml+xml (more here). After all, the W3C themselves serve XHTML 1.0 Strict as text/html.

Overall, this book was a delight to read. It covers all the important aspects of Ajax, and even shows a few server-side examples written in PHP. Multiple techniques are addressed, including XML, JSON and innerHTML.

It gets you thinking, rather than ignorantly assuming that you’re working in a controlled environment. Many server-side developers neglect accessibility and usability because they’re too busy using bloated frameworks without understanding the underlying client-side principles. Quite frankly, I’m sick of it. Luckily, there’s finally a book teaching the right way.

Page 196:

Question the way you implement Ajax. Question the impact Ajax will have on your users. Question the need to use Ajax at all.

Discuss This Topic

  1. 1 Nate Klaiber

    Great book and great review, Nathan. I think that your quotes from page 116 hit the nail on the head and sums up the core of this book – making sure you are building accessible AJAX applications. Don’t take shortcuts just to say you are using AJAX or you are ‘Web 2.0’ – understand the roles that all tools play in the process.

  2. 2 Justin Thorp

    Yeah dude! I have this book and love it. So many books talk about how to do AJAX. Very few books talk about how to do AJAX correctly. This does that.

    I also noticed that Jeremy’s voice was coming through in his writing. It made the book very easy to read.

  3. 3 Yannick

    I got this book the other day also and am loving it so far. Having read Jeremy’s DOM Scripting book, I was really looking forward to this one also. I thought that for someone like me who was just getting started with Ajax, this book was the perfect introduction.

  4. 4 Nathan Smith

    Yannick: Yeah, I was telling my wife: “Jeremy’s book is the first designer friendly JavaScript book I’ve read since… well, Jeremy’s other book.” That’s not to say there aren’t other clearly written JS books out there, but many of them use hack-ish inline JS or invalid HTML made-up attributes, etc.

    It’s nice to see tech authors who think big-picture. After all, it’s the “holy trinity” of web standards – HTML, CSS and JS. We cannot over emphasize one at the expense of the others. There must be balance.

  5. 5 Robert Spangler

    After reading your review I was pretty much sold on it!

    but then I remembered that I’m quite the newbie when it comes to JavaScript. So I’m thinking it might be better to start with DOM Scripting and work my way up to AJAX from there…What do you think?

  6. 6 Nathan Smith

    You don’t necessarily have to read DOM Scripting first, but I think that it would help to round out your overall understanding of JavaScript. That being said, Bulletproof Ajax is pretty good about establishing the basics before jumping into the crux of how Ajax works.


Comments closed after 2 weeks.