Thursday, August 31st, 2006

Mini Review of “Javascript: The Definitive Guide, 5th Edition”

Category: Book Reviews

<p>The latest edition of the venerable tome JavaScript: The Definitive Guide is a sorely needed update. I guess it took Ajax, Web 2.0, and an intervening five years to revive interest in in this quirky client-side language. The fourth edition, while still providing a good formal specification of the language, had fallen woefully out of date both with some of the new features introduced in recent browser versions and in terms of practical examples of how JavaScript is being used to enable Ajax and Web 2.0 applications.

I don’t mean to give a full review of a thousand plus page book here. Rather, I just want to focus on the chapter that covers client-side persistence. In the fourth edition, the corresponding chapter only discussed “cookie scripting.” While this chapter does talk about cookies, it delves into a number of other options for persisting data on the client.

Unfortunately, for a book that describes itself as the “definitive guide”, it only discusses three options for persistence: cookies, IE userData persistence and Flash SharedObjects. This coverage is far from definitive. In fact, Brad Neuberg in his discussion of dojo.storage enumerates seven different client-side storage mechanisms:

  1. Cookie Storage Provider – uses cookies to persist the hash table
  2. Flash Storage Provider – uses Flash’s SharedObjects to persist data
  3. ActiveX Storage Provider – uses COM’s File APIs to persist data
  4. XPCOM Storage Provider – uses XPCOM’s File APIs to persist data
  5. Form Storage Provider – uses the text autosave features of a hidden form to save transient data (the Really Simple History library uses this trick)
  6. WHAT WG Storage Provider – uses native browser persistence to store data, as defined by the WHAT Working Group.
  7. IE Storage Provider – uses IE’s proprietary abilities to store up to 60K of data.

Maybe this is just a sign that the use of JavaScript has grown so far beyond what was common or even thinkable in 2001 that it is simply isn’t possible to write a definitive guide, at least not in a thousand pages. Would you buy a book called “Java: The Definitive Guide?” Probably not.

What is there — the discussion of Flash SharedObjects and IE userData persistence — is pretty brief in comparison to the exhaustive treatment of cookie persistence. It does give you a basic description and enough code samples to get you started, but a cookbook it is not. The section on persistence alternatives has the feeling of an afterthought — something shoehorned into the book relatively late to address Ajax and Web 2.0. In fact, many parts of client-side portion of the book have that feel.

I think the book is still worth buying as a language reference, if only for its treatment of closures and object creation, but for now you’ll have to look online for more detailed, exhaustive, and “definitive” treatment of many topics.

Related Content:

Posted by Dietrich Kappe at 11:05 am
9 Comments

++++-
4.1 rating from 30 votes

9 Comments »

Comments feed TrackBack URI

check your title sp?

Mini Review of “Javascript: The Definitieve Guide, 5th Edition”

Comment by Patrick Whittingham — August 31, 2006

Thanks. Fixed.

Comment by Dietrich Kappe — August 31, 2006

I was pretty intrigued when I saw this entry in my newsreader, as I have been thinking of replacing my 4th edition with a 5th edition and haven’t found a “Definitive List of New Material” yet, but I guess I’ll have to hold off a little longer — this is little more than a rant about the lack of coverage of a fairly esoteric and young area of JavaScript development.

Comment by Erik — August 31, 2006

I got this book a few weeks ago, and haven’t gotten far into it (I’d consider myself an “expert” in javascript). It’s definitely not the most entertaining read of all O’Reilly books, but it does have some good information. I haven’t gotten up to the “Web 2.0″/AJAX/etc. sections yet, so I’m a bit disappointed to hear what is in this review. I’ve got ppk‘s book ordered too, so hopefully that will be useful in filling in the gap.

Comment by Daniel V — August 31, 2006

Erik,

Thanks to your comment, I’ve put a “definitive list of new material” up at my blog. See http://www.davidflanagan.com.

This review also appeared over at the “Agile Ajax” blog at Pathfinder. Allow me to repeat the comments I made there:

Thanks for the review of my book!

I think it is unfair to expect this book to cover every possible persistence solution, however!

I cover 3 of the 7 you list. Of the remaining four, one (forms) isn’t really persistence, since it doesn’t work across browser sessions. Another (COM) is redundant with IE’s userData mechanism. Another (XPCOM) is not (or should not be: it is not one I’m familar with) available to untrusted code. And the final one (the WHAT-WG API) is not yet widely enough implemented to be worth documenting. When it has been adopted, this will be an important API and I will cover it.

You are correct that my coverage of client-side persistance is not a cookbook: that is not the goal of this book. And you are also correct that the coverage of flash-based and userData-based persistence are kind of tacked on to the discussion of cookies. Cookies are universal, and are sufficient for most application’s persistence needs. None of the alternatives are standard or robust enough to be worth spending much time on in this book. Again, the WHATWG API may well change that, and I expect it will receive heavy coverage in the next edition of the book.

Comment by David Flanagan — August 31, 2006

Hi there, thanks for referencing the storage mechanism work I’ve done.

I think David’s book has a bit of a different goal to some of the Dojo Storage work I’ve been doing; Dojo is meant to work in any JavaScript based environment, not just in a browser. When Dojo starts up, it figures out it’s host environment and tries to work appropriately, so you could use Dojo in a Firefox extension, in a Windows Scripting Host environment, etc. Some of the storage mechanisms I describe don’t work inside of a normal browser environment; instead, they only exist in specialized JavaScript host environments. One of the promises of Dojo Storage is to give you a consistent storage API independent of the mechanism; right now we only provide a Flash based storage mechanism, but in the future I could provide one of the one’s listed in this blog post (or someone could submit one, hint hint….) So this means if you are using JavaScript in a Firefox extension, for example, you could start using Dojo Storage in a consistent way and not have to know that it is internally using XPCOM objects to persist into the file system, or using ActiveX scripting when done in a Windows Scripting Host environment.

I agree that David needed to update many of his code examples for 2006, but I don’t know if picking on his storage examples was the best place ;) His book seems to be more focused on using JavaScript in a normal browser environment then using it in other host environments.

Best,
Brad Neuberg
http://codinginparadise.org

Comment by Brad Neuberg — August 31, 2006

Interesting Finds: August 31, 2006

Trackback by Jason Haley — August 31, 2006

Do you think this book is considered a good choice for a newbie or should I want something else?

Comment by Chris — September 15, 2006

All things considered, a very good book, but… not so sure if all the code therein has been tried and tested on more than just IE + FF though. Example:
The JS from chapter 18-3, “Automatic form validation with unobtrusive JavaScript” works nicely in FF + IE, but for some reason fails miserably in the latest Opera browser (Win). Just a word of caution.

Comment by Dragan — January 22, 2007

Leave a comment

You must be logged in to post a comment.