I read Bulletproof Ajax

I and many others were excited by reading DOM Scripting by Jeremy Keith. That book can take a CSS designer with no prior JavaScript experience, and equip that reader with some easy but powerful dom-manipulating know-how, all the while reinforcing the standardista’s mantra of separation of structure, presentation, and behavior. A JavaScript beginner who reads this book can feel empowered. I read it twice, the second time with a highlighter, both times in my bed late at night with flashlight and a wife that wished I would just go to sleep and save my geekiness for the daylight hours. It was like reading a page-turning Grisham novel, except instead of a lawyer running from the mob, it was nerdy nuggets of code making html snippets move and change. With every chapter, I could not wait to get back to my computer and recreate these dynamic examples. The book is that good. Keith makes learning JavaScript that easy. The examples are real and are easily implementable to almost any site.

Jeremy Keith's books

So when Keith wrote Bulletproof Ajax, which he calls “the sequel to DOM Scripting“, you can imagine with what level of anticipation it was met, by not just myself, but many others who were also inspired by Keith’s first book. Ajax was just a casual mention in the back of DOM Scripting. With his new book, I wondered if I were going to feel that sense of empowerment again, by getting to know and understand this elusive and oft-misunderstood technology. I can’t speak for others when I talk about Bulletproof Ajax, but I’d like to give my impressions. Because the author refers to it as “sequel to DOM Scripting,” much of my review will reference both books.

The first thing I noticed was that the book was thin – less than 200 pages of content (compared to DOM Scripting‘s 300+ pages of content). That could mean one of two things – either Ajax will be much easier than I thought, or this book is not going to be as thorough as anticipated.

The first two chapters are simply introductory. Chapter one explains what Ajax is and gives alternatives to achieving similar results. Chapter 2 gives a concise summary of JavaScript that was covered in greater detail in DOM Scripting – including properties, objects, operators, etc.

Chapter 3 is where the real meat begins – an introduction to the XMLHttpRequest object. Keith walks the reader through what goes on with the XMLHttpRequest between the server and client. It’s informative and clear, though I am hardheaded enough that I will probably have to give it a third and fourth read.

Chapter 4 is another nice, meaty chapter – an explanation of the different data formats that Ajax can use, including pros and cons of each. The reader can look over these options and view which options are more suitable for their tasks. I was certain that Keith would advocate XML over the other formats (after all, it was originally the “x” in Ajax), but he doesn’t. I was partly disappointed with his explanation with the data format he chose to use for the duration of the book. He uses HTML with the innerHTML property rather than XML. innerHTML is quicker and requires less code than formatting XML. However, after having read DOM Scripting, I had been under the impression that I should probably shy away from it, since the browser is blind to the elements of code entered using innerHTML. From DOM Scripting:

… innerHTML is a proprietary method, not a web standard. I think it’s a good idea to avoid any kind of proprietary JavaScript, so that we don’t repeat the bad old days of the browser wars. … As it turns out, innerHTML is well supported. Nonetheless, its future existence is far from certain.

… the standardized DOM can be used instead of innerHTML. It may take slightly more code to achieve the same results but, as you’ll see, it offers more precision and power.

I guess “power” is relative to what your book is about. In Bulletproof Ajax, Keith repeats his concerns about innerHTML, warns against careless usage, and states he will use it anyway for the sake of brevity. It’s understandable, but I would’ve enjoyed more examples that follow in the footsteps of DOM Scripting. What if I wanted to do more DOM manipulation on the snippets of code that are injected into our AJAX examples? With innerHTML, the DOM is blind to the code within that mark-up.

Keith starts the book with a primer on JavaScript. By the time I reach the chapter on his building a full-blown Ajax application, I found myself wondering why there wasn’t a primer on PHP as well. All of the examples use it. Keith states,

Don’t worry if you don’t understand PHP. Understanding the language I’m using isn’t as important as following the underlying concepts.

But doggone it, I want both: the concepts and some understanding of the PHP code. (If I only needed the concepts, then why is there an entire chapter on JavaScript fundamentals?) Granted, many people who are familiar with PHP won’t have this complaint, but my familiarity with PHP ends at “Hello World”. If I’m going to put Ajax to work, I need to have some level of comprehension of a server-side programming language, and I think this should’ve been mentioned in the introduction, which currently states the following:

If you’re a front-end developer, this is the book for you. You’re probably well-versed in Web Standards. I trust you’re using semantic markup and CSS, perhaps even some rudimentary DOM Scripting. If so, read on.

As stated, I would add to that list that any potential reader should also have some basic-to-intermediate PHP knowledge especially if you’re wanting to implement the examples. Be capable of writing a form in PHP that has server-side field validation to get the most from this book. Chances are if you know how to do that, you can implement the rest of the examples and be ready to cater them to your own site. Ajax can be applied to any server-side language, not just PHP, but I think it would be helpful when following his examples if the reader could grasp PHP syntax.

The server-side code isn’t completely left unexplained, and code for all examples are found on the web site for reference, but the level of detail is not as equal to that for the JavaScript.

That said, having to cover JavaScript, CSS, HTML, and PHP (especially when PHP may not be the reader’s server-side language of choice) is a daunting task for an author, and Keith manages to convey the concepts with relative ease, even if there isn’t a full explanation of the code.

Bulletproof Ajax excels at covering the accessibility challenges of Ajax. Web Standards are upheld and encouraged throughout the book. Keith constantly asks, “Is Ajax the best way to do this?”. He recognizes how enthusiastic designers can get at the mention of this buzzword, and he feels responsible enough to keep the reader’s excitement in check, and remind them that Ajax is just one tool out of many that can be used to enhance web sites without sacrificing accessibility.

As for Ajax concepts in the world of Web Standards, Bulletproof Ajax is an essential read. However, rather than refer to it as “the sequel to DOM Scripting“, I would instead think of it as the third book in the following trilogy:

  1. DOM Scripting
  2. Some server-side language beginner book, PHP preferred
  3. Bulletproof Ajax