An offline-capable app needs to know whether its local data is nearing a storage limit—and whether the browser may evict that data. The Storage API provides origin-level usage estimates, quota estimates, and persistence controls. It does not store data; use a storage API suited to the data, such as IndexedDB, Cache Storage, or OPFS. section 12.4.3 section 12.5
if (navigator.storage?.estimate) {
const { usage, quota } = await navigator.storage.estimate();
console.log(`Using ${usage} of ${quota} bytes`);
}
Check for support before calling `navigator.storage.estimate()`. Its `usage` and `quota` values are approximate, not exact measurements or fixed allocations; available quota varies with the browser, device, mode, and settings. section 12.4.3
Most origin storage is best effort: the browser may evict it under storage pressure or after inactivity. The quota bucket commonly includes IndexedDB, Cache Storage, OPFS, service worker registrations, and—in most browsers—local storage. It usually excludes cookies, sessionStorage, the regular HTTP cache, and files explicitly chosen by the user. section 12.4.3
if (navigator.storage?.persisted) {
const alreadyPersistent = await navigator.storage.persisted();
console.log("Already persistent:", alreadyPersistent);
}
if (navigator.storage?.persist) {
const granted = await navigator.storage.persist();
console.log("Persistent storage:", granted);
}
If offline data is important, check `persisted()` and request persistence with `persist()` where available. Treat the result as a grant decision, not an assumption. Browsers may use heuristics to decide; Firefox may ask the user. section 12.4.3
Persistence protects against eviction solely due to storage pressure, not user deletion, profile loss, device resets, or app bugs. For important local data, provide an export or synchronization path; plan for quota errors and validate restored data. section 12.4.3 section 12.5
