June 16, 2010

USTORE.js – cross browser local and session storage

(Because you don’t have to listen to me) –> Check out USTORE.js @ github, or check out the JS file itself!

Two of the cooler new features in the HTML5 spec are localStorage and sessionStorage. You might wanna think of them like cookies, but on steroids.

LocalStorage allows for data, in name value pairs, to be stored within the web browser. This data will persist past window closures and browser crashes, and will stay consistent across multiple tabs & windows of the same URL.

SessionStorage is exactly the same as localStorage with a difference – the data only lasts for the life of the browser window. If the window is closed, or the browser crashes, the data is dumped. The data will be independent across multiple tabs & windows of the same URL.

Native support for the localStorage and sessionStorage API’s can be found in the latest versions of Firefox, Chrome, Safari, and Opera, and even IE8! So as usual, the nut to crack lies in how do we get this to work in IE6 & IE7?

Well, there is a jQuery plugin out there called jStorage, among a few others, that successfully emulates localStorage across all the major browsers, including IE6+. But what of sessionStorage?

While working at HUGE, I’ve been able to put together a small javascript library that does just that. Both local and session storages are supported by USTORE.js.

Check it out @ github, or check out the JS file itself! Official docs will be coming soon.

RSS feed for comments on this post.

  1. Kenny Katzgrau — June 16, 2010 @ 2:23 pm

    Sweet deal. I’m going to have to put something together about this @ my blog too.

  2. Dwight Vietzke — July 27, 2010 @ 3:34 am

    Hi Sankho,

    Nice script. Very compact. I will have to give it a try. I like the fact it doesn’t rely on another massive javascript framework in order to function. Thanks for the post.

  3. sankho — July 27, 2010 @ 3:44 pm

    Yeah, originally it was written as a jQuery plugin but then I thought… why? Lemme know if it helps out!

  4. Flame — August 18, 2010 @ 7:48 am

    You thought why?
    I can’t believe you didn’t leave it in jQuery.

  5. sankho — August 20, 2010 @ 1:07 am

    jQuery messes with the DOM… localStorage doesn’t need to.

Leave a comment

Best of Blog

  1. Let’s do the kids a favor: HTML as a classroom language
  2. USTORE.js – cross browser local and session storage
  3. Add Facebook Connect to your PHP Web App
  4. Setting up your website on Rackspace Cloud Servers – Manage Your Own Hosting
  5. Tutorial: Using Zend_Captcha_Image

Search if you must