Answer
IndexedDB vs localStorage: which should a PWA use?
localStorage is a simple synchronous key-value store limited to strings and roughly 5-10MB, and it is not accessible from inside a service worker. IndexedDB is an asynchronous, transactional database that can store structured objects, blobs and much larger amounts of data, and it is accessible from both the page and the service worker — making it the right choice for most PWA data storage.
Why service workers matter here
localStorage is synchronous and blocks the main thread; it is also unavailable inside a service worker at all, which rules it out for offline-first data that needs to be read during a fetch event.
Capacity
localStorage is capped around 5-10MB per origin depending on the browser; IndexedDB shares the much larger Cache Storage quota, often hundreds of MB to GBs.
Ease of use
IndexedDB’s raw API is verbose, which is why most teams use a wrapper library like idb or Dexie.js rather than the native API directly.