localStorage is a new JavaScript API in HTML5 that allows us to save data in key/value pairs in a user’s browser. It’s a little bit like cookies except:
- Cookies expire and get cleared a lot, localStorage is forever (until explicitly cleared).
- localStorage isn’t sent along in HTTP Requests, you have to ask for it.
- You can store way more data in localStorage than you can in cookies.
- The API for localStorage is wicked simple and easy.
If you need to get more up to speed, I did a video screencast on localStorage recently. This is how it works:
/* Set some data */
localStorage.setItem("key", "value");
/* Get some data */
localStorage.getItem("key");
No libraries needed, that’s just JavaScript. If you want you can use Modernizr to test for it with Modernizr.localstorage first.
OK great that’s all the geeky bits, let’s see some places on the web that could be, should be, or are using it. Hopefully this will spark some ideas for your own websites.