Storage Quotas And Eviction
Offline data is only as safe as your storage and recovery plan.
Storage Risk Model
| Risk | Mitigation |
|---|---|
| Browser evicts origin data | Request persistent storage where appropriate, but also provide export/backup |
| User clears site data | Make clear what local-only data means; sync or export important records |
| Private browsing limits storage | Detect failures and warn users before they rely on offline data |
| Quota exceeded | Track usage, cap caches, compress or expire blobs, provide cleanup |
| Origin changes | Keep production origin stable; migration across domains needs export/import or server sync |
| Opaque cache responses consume space | Avoid caching third-party opaque responses unless necessary |
Quota Check
if ('storage' in navigator && 'estimate' in navigator.storage) {
const estimate = await navigator.storage.estimate();
const used = estimate.usage ?? 0;
const quota = estimate.quota ?? 0;
console.log(`Using ${Math.round((used / quota) * 100)}% of quota`);
}
Cleanup Policy
- Expire runtime caches by age and count.
- Store large user files intentionally, not as incidental cache entries.
- Keep export paths for records users cannot recreate.
- Separate clear-cache from delete-user-data in UI.
- Test storage pressure before promising offline-first.