Advertisement
Intermediate JavaScript, Browser Storage & Web APIs

What are the size limits of localStorage compared to IndexedDB?

Short answer

localStorage is typically capped around 5–10MB per origin and is synchronous, which can block the main thread on large reads/writes. IndexedDB supports much larger amounts of data (often hundreds of MB or more, browser-dependent) and is fully asynchronous.

Save JavaScript mock interview
Advertisement
AModel answer
localStorage is typically capped around 5–10MB per origin and is synchronous, which can block the main thread on large reads/writes. IndexedDB supports much larger amounts of data (often hundreds of MB or more, browser-dependent) and is fully asynchronous.
// localStorage: simple, small, synchronous
localStorage.setItem('flag', 'true');

// IndexedDB: larger, async, more setup
const request = indexedDB.open('MyDB', 1);
Real-world example
Using IndexedDB to cache an offline-capable app's entire product catalog, which wouldn't fit in localStorage.
Likely follow-ups
  • When would you choose Cache API over IndexedDB for offline data?
Related topics