Storage Quotas And Eviction

Offline data is only as safe as your storage and recovery plan.

Storage Risk Model

RiskMitigation
Browser evicts origin dataRequest persistent storage where appropriate, but also provide export/backup
User clears site dataMake clear what local-only data means; sync or export important records
Private browsing limits storageDetect failures and warn users before they rely on offline data
Quota exceededTrack usage, cap caches, compress or expire blobs, provide cleanup
Origin changesKeep production origin stable; migration across domains needs export/import or server sync
Opaque cache responses consume spaceAvoid 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.