Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Making Use of HTML5 Storage (developerdrive.com)
30 points by parmgrewal on March 12, 2012 | hide | past | favorite | 3 comments


I really like using HTML5 Storage since it's so easy to implement.

There's one thing you forgot to mention. You can also add arrays and objects to HTML5 Storage using JSON.parse and JSON.stingify as listed below.

var testObject = { 'one': 1, 'two': 2, 'three': 3 };

// Put the object into storage localStorage.setItem('testObject', JSON.stringify(testObject));

// Retrieve the object from storage var retrievedObject = localStorage.getItem('testObject');

console.log('retrievedObject: ', JSON.parse(retrievedObject));

I literally got this from stackoverflow (http://stackoverflow.com/questions/2010892/storing-objects-i...)

Coincidentally I was building a small javascript bookmarklet for myself this weekend using localStorage. The bookmarklet allows you to make playlists on the fly. Check it out on http://www.jefvlamings.com/projects/Youtube/


This is a good start, but I would like to see more real world experience on 1) How will this benefit w.r.t replacing or using alongside Sessions (HttpSession in java for example) 2) Size limits - 5mb and 1mb for IE7, storages different per scheme/domains 3) Data Security


The size limits are more complicated, because strings get stored as utf16, so that 5 mb is a lot less in practice. Also, on ie7, you have to fall back to userData whose capacity depends on the security zone your app runs in, and can get as low as 64 kb.

I use it to replace cookies for storing settings that don't need to get sent to the server on every request. The collapsed state of a sidebar for example.




Consider applying for YC's Fall 2025 batch! Applications are open till Aug 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: