« The hard truth regarding employee happiness

d’bug update — down and dirty with jQuery »

Book review: jQuery in Action

April 3rd, 2008 by Brian | 3 Comments »

Book: jQuery in ActionThere are very few technical books that I read, or use as an ongoing resource, which allow me to state with confidence that they are worth the money I paid. jQuery in Action would be one such book. Of course, in the interest of full disclosure, I did not pay for the book. I was given a digital copy by the publisher for review. Nonetheless, these pages are packed full of API documentation and tutorials, and if I were just beginning my journey with jQuery, I would pay for jQuery in Action.

Even with that glowing introduction, I still take issue with how a few of the concepts were organized and presented in the book. It could simply be that the official jQuery documentation is so well thought out that I find myself increasingly critical of any author’s attempts to expound upon it. I doubt that is wholeheartedly the case, and in an attempt to remain unbiased you might find this review overtly detailed in scope. In my opinion this is necessary not only because I am very supportive of the jQuery JavaScript framework, but because of the depth of the material.

Summary

The authors for jQuery in Action maintain a consistent voice throughout, and the entire overview of the framework strikes a nice balance between a strict reference and a cookbook. If you feel that the documentation on jQuery.com is not to your liking, and you simply want an alternative API reference, then I would suggest instead jQuery Reference Guide, by Jonathan Chaffer and Karl Swedberg. However, given a choice between Learning jQuery and jQuery in Action, I would personally choose the latter. Both books do an excellent job, but Bear Bibeault and Yehuda Katz take jQuery in Action to a more extreme examination of the JavaScript and jQuery relationship.

This intense detail can be a pitfall depending on your comfort level with JavaScript. As much as I would like to believe the book is for all ranges of expertise, I do not believe it is for beginners who have no (or very little) JavaScript experience. Neither is it for designers looking only to compliment their portfolio with some rich effects. Quite frankly, this is a market that has yet to be penetrated with force, and the Web site jQuery for Designers is as close as any medium has come to meeting the demand.

The book does have a nice top-down approach, starting with the basics, but moving quickly into more advanced topics. The only structural change I would suggest would be to swap chapter seven and chapter eight in your order of reading. The subject of AJAX and XHR (chapter eight) is too important to follow plugin authoring (chapter seven), which makes more sense as a precursor to chapter nine, a review of official jQuery plugins. Everything else falls nicely into place, and I never felt lost.

The only thing I truly desired that was missing, and which could be added in a second printing, would be academic exercises at the end of each chapter. Even though I know jQuery, I found myself wanting to be challenged in some way. There are labs throughout that demonstrate the capabilities of the library, but these act more as a visual playground. I think that Web developers could really benefit from Bibeault’s and Yehuda’s experience by having them throw down the gauntlet. Providing solutions on an accompanying forum (which does exist for the book by the way) would have been a great addition.

On the flip side, the only thing I would remove (or enhance) in the book is the screenshots. I had a similar complaint about Learning jQuery, and if developers truly want to benefit by pulling in the design crowd, then the labs, diagrams, and code snippets really need a more contemporary feel. The text on the diagrams and screenshots was difficult to read, and the busy gradients used in the graphics really deterred from the simplicity of the techniques demonstrated. Although the authors did a great job of teaching the material, the visual cues were lacking.

Chapter 1: Introducing jQuery

This chapter was a light introduction to jQuery, and the zebra striped tables example was a good way to break the ice. The authors stress the importance of unobtrusive JavaScript throughout book, and this example begins that education. It was a nice touch, and I was happy to read about responsible development tactics, and how these practices can affect the UI.

I was not too keen on some of the inconsistencies regarding the jQuery and JavaScript syntax, but I am noted as being a stickler in this area. I want all expressions and loops to be formatted properly (the same), curly braces applied, and tabs spaced accordingly. One could certainly argue that most technical books fall short in this area in one way or another, and it does not truly detract from the content.

Chapter 2: Creating the wrapped element set

This chapter introduces the first of several labs, and it was certainly a unique method of educating developers on features and functionality. The overview of jQuery selectors was excellent, and plenty of examples were given to teach developers about how easy manipulating the DOM can be with this JavaScript framework. Most novice developers will initially overlook the power of snippets like the following:

var n = $(’img’).index($(’img#findMe’)[0]);

Yet, this sampling is powerful, and these little nuggets of wisdom are strewn about in every chapter. Even after using jQuery for so long I found myself wondering why I was not using some of these techniques instead of implementing some complicated and unnecessary logic. The only complaint I had was that the callback function should have been introduced in this chapter, or the previous chapter. Instead it ended up with an explanation in the appendix, which I thought minimized its importance.

Chapter 3: Bringing pages to life with jQuery

This chapter is very similar to chapter two, which is understandable since selectors are such an engrossing topic. The separation of getting and manipulating elements from the DOM (chapter two), and manipulating the DOM itself (chapter three) is certainly necessary so as not to inundate developers in one fell swoop. Do not skim this chapter thinking you have had your fill from the previous chapter. You will be missing out on some useful knowledge.

My jQuery version may be out of date, but I am quite sure that the $.html() command can not be used to retrieve what is inside an XML node, and that only the $.text() command will work. This distinction should have received a brief mention to save developers some headache. Also, the $.wrap() command is complicated, and I would have liked to read a more in depth example as a compliment to the $.append() command overview.

Chapter 4: Events are where it happens!

This chapter is where many novice developers or designers may fall off the wagon. The first call out highlighting the appendix is at the beginning, and if you are brave enough to read that first and then make a round trip back without too much confusion, then you are in good shape. I appreciate what the authors are trying to do within the context of the book, and the explanation of the event model is concise and well done. However, I get a sense that most readers will skim through this and get right to the heart of the chapter, which is the excellent discussion of jQuery’s event handling. If you are a beginner, I would implore you not to do this, since Bibeault’s and Katz’s summary of event models is one of the best I have read.

The ability to namespace event binding was a good trick that not many jQuery developers use (myself included), and it takes some forethought to implement. Again, this was one of those nuggets that at first glance appears unsophisticated, but the ability to unbind several events at once is amazingly useful.

One area likely to cause some argument among seasoned developers, is the use of custom attributes on elements in order to easily access certain values (like item pricing) with jQuery. I would disagree with the authors on the approach (not on the basis of validating your document) because there is a much easier technique — use hidden fields. An alternative suggestion was the use of an object hash to store things like price data, but you will find that hidden fields are a better route.

Chapter 5: Sprucing up with animations and effects

The nested collapsible list was a great way to start the chapter, and this example truly demonstrates the power of jQuery. I am sure many developers and designers will find this a refreshing change from the technical discussion in the previous chapter. There is not a lot of dramatic flare to speak of in the example, and I found myself wanting to do more, and to be challenged to do more. There is certainly nothing missing in relationship to the techniques that are covered, but this gets back to jQuery for designers. I also understand that this is not a cookbook, but I really longed for some sweet piece of production code that I could slap onto my site at a moment’s notice.

Overall, this is a chapter that you will return to often, and you will quickly discover why jQuery has an advantage over other frameworks because the developers took the time to provide just the right amount of flexibility in regards to animation. Combine the custom photomatic plugin built in chapter seven with the techniques learned here, and you will enjoy tinkering with jQuery for weeks to come.

Chapter 6: jQuery utility functions

I really enjoyed chapter six, since it took a good look in length at the utility functions that you will use constantly in just about every jQuery project. To me this was the best chapter in terms of sample code, discussion, and tips and tricks. I found myself whipping along, and thinking afterwards that it was just a nice, comfortable read. The description of the $.each() method falls a little short because it shows how to iterate over object collections, but not a collection of elements belonging to the jQuery object — this happens instead intermittently in other chapters.

There is an awesome example for $.grep(), which works in tandem with regular expressions. Be sure to put this snippet into your bag of tricks as well as the sample $.map() command. These are intermediate to advanced techniques that will serve you well on demanding projects.

Chapter 7: Extending jQuery with custom plugins

To date, this is close to the best description of plugin development that I have read. (The description from Learning jQuery would be an equivalent match.) Along with chapter five, designers and interface developers will find themselves coming back to this chapter often. The authors do an excellent job of describing the creative process, or spirit behind creating a plugin. Other tutorials often spend too much time on the mechanics, and it was a welcome change to read up on best practices when considering a plugin solution.

Without meaning to, the authors introduced an advanced design pattern that allows developers a method of overloading functions by passing an object hash as an argument to that function. Good stuff! The $.toFixedWidth() and $.formatDate() methods are the perfect real-world examples of utility functions, and the $.setReadOnly() and $.photomatic() are nifty wrapper methods as well. These are the closest representations of production-ready code found in the entire book.

Chapter 8: Talk to the server with Ajax

Similar to how chapter four covers events, this chapter delves deeper into AJAX and XHR JavaScript concepts before moving onto jQuery specific implementations. It was a nice summary, and this information adds an increased level of professionalism to jQuery in Action. The Boot Closet sample application could have been reigned in a bit, and the authors even state that it is no surprise it is one of the longest chapters in the book.

I was a little confused by the decision to suggest JSP and a servlet container like Tomcat, instead of just using PHP and Apache HTTP Server. The only reason a local server is necessary at all unfortunately is because IE falsely identifies a cross-domain security issue when making XHR calls from the file system. Also, unless I am mistaken, it is not possible to load a JSP file into an HTML file without first setting up .html as an alias for .jsp in Tomcat. This is a lot of overhead for a tutorial, which can be eliminated by simply suggesting readers use PHP.

The following description of the response received in an XHR call was slightly misdirected. The authors state that,

It could be plain text or, perhaps, an HTML fragment; it could even be a text representation of a JavaScript object or array in JavaScript Object Notation (JSON) format.

The reality is that the response can only be plain text or XML. You would then use jQuery to evaluate that response as plain text, JSON, or an HTML fragment. Also, the note that GET requests are highly subject to caching could have been followed up with the fact that with a servlet container like Tomcat, it is almost always necessary to pass a parameter with the current date/time in the request so that the server knows it is a brand new request.

Chapter 9: Prominent, powerful, and practical plugins

You are probably exhausted with this review by this point, and you will be happy to know I have little to say about chapter nine. The authors did an excellent job covering the most popular jQuery plugins: Form, Dimensions, Live Query and UI. This chapter was a nice addition, and an added bonus.

Appendix: JavaScript that you need to know but might not!

I usually would not cover the appendix in a book review, but because such attention was drawn to it I had to read it diligently. Honestly, this is the most complicated aspect of the entire book. First-class functions and objects are not typically concepts most developers would learn about outside of an academic setting. Also, the explanation of closures was too intermediate, and I doubt the novice will take much away from it. This relationship to jQuery actually has more to do with the scope of (local) variables contained within jQuery wrapper methods, and not necessarily closures. In summary, not a bad bit of information, but it could have been simplified.

Conclusions

The best advice I can offer is to buy the book. If you know full well that you will be using jQuery (or are interested in using jQuery) on future projects, then jQuery in Action will provide you with everything you need. There are no glaring shortcomings in the book, but I would certainly take note of the feedback I gave in this review. This will help you to get into your reading with realistic expectations. Congrats to Bear Bibeault and Yehuda Katz on a job well done.

About the Authors

Bear Bibeault

BEAR BIBEAULT has been writing software for over three decades, starting with a Tic-Tac-Toe program written on a Control Data Cyber supercomputer via a 100-baud teletype. Because he has two degrees in Electrical Engineering, Bear should be designing antennas or something; but, since his first real job with Digital Equipment Corporation, he has always been much more fascinated with programming.
- Excerpt from jQuery in Action

Yehuda Katz

YEHUDA KATZ has been involved in a number of open-source projects over the past several years. In addition to being a core team member of the jQuery project, he is also a contributor to Merb, an alternative to Ruby on Rails (also written in Ruby).
- Excerpt from jQuery in Action

jQuery in Action Resources

Table of Contents

http://www.manning.com/bibeault/excerpt_contents.html

Tags: ,

Posted in: Book Reviews

This entry was posted on Thursday, April 3rd, 2008 at 3:16 am and is filed under Book Reviews.

You can follow any responses to this entry through the RSS 2.0 feed.

Both comments and pings are currently closed.

3 Responses to “Book review: jQuery in Action”

  1. Snef says:

    Thanks for the review!

  2. Bud Gibson says:

    I’m considering using this book in a capstone course at Eastern Michigan University (yes, the one right next to you). I agree with your assessment that it is not for the novice, though it oddly claims to be. Would you be available to have lunch or coffee? I’d like to talk over some course design ideas with you.

  3. Brian says:

    Hi Bud,

    I’d be happy to meet up and discuss over lunch or for coffee after work. Feel free to email me directly — blog [at] reindel [dot] com, and we can setup a time.