Store JS-objects in HTML5 Web Storage

Published: 30. October 2011

When I was creating tudoo, I wanted to store my todo-items in Web Storage (aka localStorage).

The problem about Web Storage, is that it's really just a key/value pair dictionary, that can only contain string values. It's very simple to use:

One thing to note, is that the data is shared across a origin. So watch out if you have multiple HTML5 apps, that they don't overwrite each other. Also note that there is a max of data you can store. This are independent of the browser the user uses. (typical 5mb, but it is a user setting, so you never know)

Anyway, to store complex objects, the trick is simply to convert your object to json:

Be awesome - write more JS :)

Comments

Write a comment


You can use Markdown formatting