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:
- Cookie Storage Provider - uses cookies to persist the hash table
- Flash Storage Provider - uses Flash’s SharedObjects to persist data
- ActiveX Storage Provider - uses COM’s File APIs to persist data
- XPCOM Storage Provider - uses XPCOM’s File APIs to persist data
- Form Storage Provider - uses the text autosave features of a hidden form to save transient data (the Really Simple History library uses this trick)
- WHAT WG Storage Provider - uses native browser persistence to store data, as defined by the WHAT Working Group.
- 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.