Skip to content
Web Design & Development

A Practical Guide to Web Storage and IndexedDB

The browser storage options for websites, from localStorage and sessionStorage for small values to IndexedDB for larger structured data.

MediaScaleUp Editorial Team 2 min read 9 views
A Practical Guide to Web Storage and IndexedDB

Why does it matter?

Choosing the wrong storage causes performance problems and security risks, especially when sensitive data ends up somewhere scripts can read it.

What are the numbers?

  • localStorage synchronous, string-only and persistent until cleared
  • sessionStorage limited to a single tab's session
  • IndexedDB asynchronous storage for larger structured data
  • Security any script on the page can read web storage, so it should not hold secrets

What should I do?

  1. Use localStorage only for small, non-sensitive preferences
  2. Use IndexedDB for offline data
  3. Handle storage being unavailable or full
  4. Clear stored data on sign-out
  5. Version stored data formats
What to do and what to avoid with web storage and IndexedDB, side by side
Good practice against the usual mistakes, from the sources listed below.

What should I avoid?

Avoid:

  • Storing tokens or personal data in localStorage
  • Large synchronous reads on page load
  • Assuming storage always persists
  • Unbounded caches that fill the quota

When should I get help?

Short answer Bring in help when building offline features, or when a security review flags data stored in the browser.

Where this comes from

The figures and practices above come from the sources listed.

Working on something like this?

We take on Web Design & Development work for teams who want it done once, properly. Tell us what you are building and we will tell you honestly whether we are the right studio for it. Start a project.

Where to go next

Spotted something wrong? Report an error on this page. We correct on the page and say what changed.

All services

The work behind this article, and what it costs.

MediaScaleUp Editorial Team

Articles here are researched, written and checked by the MediaScaleUp studio team before they are published, and dated when they are reviewed.

Keep reading

More in Web Design & Development