Quota and persistent storage
How much storage does the browser give you?
Section titled “How much storage does the browser give you?”Browsers do not give every origin unlimited storage. Instead they allocate a quota — a maximum amount the origin may use — based on available disk space and browser policy. The quota for IndexedDB, Cache API, and OPFS comes from a shared pool called the “default” storage bucket.
The navigator.storage.estimate() API returns a snapshot of how much of that quota your origin has consumed.
const { quota, usage } = await navigator.storage.estimate();console.log('Quota :', (quota / 1024 / 1024).toFixed(1), 'MB');console.log('Usage :', (usage / 1024 / 1024).toFixed(2), 'MB');The returned usage figure covers IndexedDB, Cache API, and OPFS together. It does not include localStorage or cookies, which have separate, smaller limits.
Best-effort vs persistent storage
Section titled “Best-effort vs persistent storage”By default, every origin gets best-effort storage. Under low disk space the browser is free to evict best-effort data — silently, without warning — to reclaim room. The eviction order is typically least-recently-used origin first.
You can ask the browser to upgrade your origin to persistent storage. Persistent data is never evicted without an explicit user action (clearing site data). To request it:
const granted = await navigator.storage.persist();console.log('Persistent storage granted:', granted); // true or falseTo check the current state without requesting:
const isPersisted = await navigator.storage.persisted();console.log('Already persistent:', isPersisted);When does the browser grant persistence?
Section titled “When does the browser grant persistence?”Browsers use engagement heuristics to decide whether to grant the request silently or show a permission prompt. Factors that increase the likelihood of an automatic grant include:
- The site is installed as a PWA (added to Home Screen / installed via browser UI)
- The user has visited the site frequently
- The user has bookmarked the site or granted other permissions (push notifications, geolocation)
- Some browsers (Firefox) always ask the user; Chromium-based browsers may grant silently
Two storage durability tiers
Section titled “Two storage durability tiers”flowchart TD
A[Origin stores data] --> B{Durability tier}
B -->|Default| C[Best-effort storage]
B -->|After persist granted| D[Persistent storage]
C --> E[Browser MAY evict under\ndisk pressure]
E --> F[Data silently deleted]
D --> G[Browser will NEVER evict\nwithout user action]
G --> H[Data safe until user\nclears site data] Runnable: check your quota and persistence state
Section titled “Runnable: check your quota and persistence state”The snippet below calls both estimate() and persisted() and logs the results. No demo keys are written — the estimate API needs no cleanup.