When web applications store hundreds of megabytes of media, offline databases, and application assets via IndexedDB and the Cache API, browsers enforce storage management policies. Understanding Storage Quotas, eviction algorithms, and requesting Persistent Storage ensures your app's offline data is never unexpectedly purged by the browser.
1. Storage Quotas: Best-Effort vs. Persistent
By default, all web storage (IndexedDB, Cache API, LocalStorage) operates in Best-Effort mode:
Best-Effort Storage: If device disk space runs critically low, the browser's storage manager automatically evicts (deletes) entire origin storage trees without asking the user, using an LRU (Least Recently Used) policy!
Persistent Storage: Data is guaranteed not to be deleted by automatic browser clearing. It can only be cleared if the user explicitly clears browser data.
1Storage Mode:
2 ├── Best-Effort (Default) ──► Low Disk Space? ──► Silently Deleted by Browser!
3 └── Persistent Storage ──► Low Disk Space? ──► PRESERVED! User must manually clear.
2. Inspecting Storage Quota with navigator.storage.estimate()
To monitor available space and consumption in bytes:
13 console.log('Data is protected from automatic browser eviction.');
14}else{
15 console.log('Operating in best-effort storage mode.');
16}
17}
18}
19}
Browser Granting Heuristics:
Browsers (Chrome, Firefox, Safari) may grant persistent storage automatically without a prompt if:
The site is installed as a PWA (added to home screen).
The user has bookmarked the site.
The user has high engagement (frequent visits).
Push notification permissions have been granted.
4. Handling Storage Overflows: QuotaExceededError
When attempting to store data beyond the allowed quota, operations throw a QuotaExceededError (DOMException code 22). Always catch this error defensively: