Capacity and Limits
You'll learn how localStorage, IndexedDB, and the Cache API differ in storage capacity, size restrictions, and what happens when they run out of space.
Understanding Browser Storage Limits
Each browser storage mechanism comes with different constraints—think of them like containers: localStorage is a small jar, IndexedDB is a warehouse, and the Cache API is a loading dock with flexible space.
localStorage Capacity
localStorage typically offers 5–10 MB per origin (varies by browser). It stores simple string key-value pairs, so this limit fills up quickly with large datasets. When exceeded, you'll encounter a QuotaExceededError.
IndexedDB Capacity
IndexedDB provides significantly more room—often starting at 50 MB minimum, with the potential for gigabytes depending on available disk space and browser implementation. Chrome and Firefox may grant more storage based on your device's free space. IndexedDB uses a quota management system where you can request persistent storage to avoid automatic eviction.
Cache API Capacity
The Cache API shares quota with IndexedDB (both use the same storage pool). It can store large assets like images, scripts, and HTML files efficiently. Limits are generous—typically hundreds of megabytes to several gigabytes—making it ideal for offline-first applications.
Eviction Policies
When storage fills up:
- localStorage: Oldest data isn't automatically removed; you must manually clear it
- IndexedDB/Cache API: Browsers may evict data marked as "best effort" when device storage runs low. Persistent storage (requested via Storage API) protects critical data from automatic removal
Key Takeaway: localStorage has strict 5–10 MB limits for simple data; IndexedDB and Cache API share much larger quotas (50 MB+) and support eviction policies, with Cache API excelling at storing large files for offline use.