HTML5 localstorage

Dec 9, 2010 · Follow on Twitter and Mastodon javascript

I have spent some time experimenting with the new HTML 5 localStorage feature, which is a new feature that simplifies storing data in the browser using JavaScript.

For instance, say that you have a web application that needs to uniquely identify the device. The device itself doesn’t send information like the MAC address, phone number etc. so, you’re at a loss.

You can then easily create a unique ID and store it in local storage. The browser can then use the persisted to identify itself consistently until the user clears the local storage.

This is all you need to store a small string in local storage:

localStorage.setItem("name", "Daniel");
var name = localStorage.getItem("name");
localStorage.removeItem("name");

Local storage does NOT replace a real database, since it’s unique for each browser and can’t hold large amounts of data. It’s however great for smaller pieces of data.

Discussions & More

Please share any ideas, feedback or comments you may have in the Disqus section below, or by replying on Twitter or Mastodon..

If you found this text interesting, make sure to follow me on Twitter and Mastodon for more content like this, and to be notified when new content is published.

If you like & want to support my work, please consider sponsoring me on GitHub Sponsors.