Client-Side Storage in Javascript

Thomas Frank published an awesome hack back in January. Somehow I missed it at the time, but the ever-vigilant Simon Willison picked it up yesterday.

The short version is that by serialising a data structure to the window.name property in the browser DOM you can store up to 2MB (much more in some browsers, eg. IE:32MB, Safari:64MB) for the life of that window object, so a single-window session (multiple tabs or windows open on a page at the same time would not have access to the same data).

Besides from begging the question of what browser developers have been smoking, this isn’t a revolution… The HTML 5 working draft features structured client-side storage so this was already on its way via a more formal route. There are also other methods in place to accomplish similar things, for example Dojo uses the Flash plugin where available to achieve client-side storage.

That said, I’d be surprised if this method didn’t sneak its way into a few codebases here and there due to it’s simplicity, broad browser support, and immediacy… and once Javascript developers become more accustomed to the concept of client-side storage we may well see a flurry of new techniques built on client-side storage.

Advertisements

One Response to Client-Side Storage in Javascript

  1. The advantage of using flash & javascript is that you can share the cookie with all the browsers and even if the user clean the cache and cookies, the values will persit (per domain) because it uses the SharedObject.getLocal of flash (AS), flash has an east way to communicate javascript with flash using ExternalInterface.

    example (Movie.fla)

    //Will execute a js function name flash_ready passing
    // the string ‘ok’ as an argument
    ExternalInterface.call(‘flash_ready’,”ok”);

    //Let the com. open to javascript to call a flash function
    ExternalInterface.addCallback(getFunction, null, getRealFunction)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: