How to Manage Service Worker Cache Storage Quotas and Eviction Policies in Google Chrome

Modern Progressive Web Applications (PWAs) rely heavily on the Cache Storage API and IndexedDB to deliver instant offline functionality and cache rich media assets. However, browser storage is not limitless: Chromium engines allocate origin storage dynamically based on overall disk capacity. If the host disk experiences storage pressure, Google Chrome automatically evicts data from origins categorized under "best-effort" storage. For offline applications, silent cache eviction causes broken user workflows and unexpected asset re-downloads. In Google Chrome, developers must proactively inspect quota usage and request persistent storage locks.

Understanding Chrome Storage Quota Buckets and Eviction

Google Chrome allocates storage quotas through a pool-based architecture:

  • Origin Quota Allocation: By default, a single origin can utilize up to 60% of total disk space, subject to available device head-room.
  • Best-Effort vs Persistent Storage: By default, all origins operate in "best-effort" mode. When available device disk space drops below critical thresholds, Chrome purges data from the least-recently used (LRU) origins.
  • Persistent Storage Mode: Once granted persistent status via the Storage API (navigator.storage.persist()), Chrome guarantees that Cache Storage and IndexedDB tables will never be evicted automatically during low-disk states.

Requesting Persistent Storage and Auditing Quota in JavaScript

Implement resilient quota checks and persistent storage requests during application bootstrapping:

// Bootstrap storage quota verification
async function verifyApplicationStorage() {
    if (navigator.storage && navigator.storage.estimate) {
        // Query current quota and usage
        const { quota, usage } = await navigator.storage.estimate();
        const percentUsed = ((usage / quota) * 100).toFixed(2);
        console.log(`Storage used: ${(usage / 1048576).toFixed(1)} MB of ${(quota / 1048576).toFixed(1)} MB (${percentUsed}%)`);

        // Check whether persistent storage is active
        const isPersisted = await navigator.storage.persisted();
        if (!isPersisted) {
            // Request persistent lock
            const granted = await navigator.storage.persist();
            console.log(granted ? "Persistent storage granted!" : "Persistent storage declined by browser.");
        }
    }
}

verifyApplicationStorage();

Auditing Cache Storage Quotas in Chrome DevTools

To inspect active quota usage and simulate storage pressure in Google Chrome:

  1. Open Google Chrome and navigate to your application.
  2. Open Chrome DevTools by pressing Ctrl + Shift + I (or Option + Command + I on macOS).
  3. Switch to the Application tab and click on the Storage category in the left tree.
  4. Examine the visual pie chart: Chrome displays exact megabytes utilized by Cache storage, IndexedDB, and Service workers alongside total available quota.
  5. Check the Simulate custom quota checkbox to test application behaviour when disk limits are constrained (e.g. simulating a 50MB quota).
  6. Inspect individual caches under Cache storage to verify that response headers contain valid content-length and cache-control metadata.

Designing Proactive Cache Eviction Handlers

Never assume infinite storage capacity. In your Service Worker code, track the number of cached items and implement an LRU cache eviction loop to delete outdated media chunks or stale API responses once a bucket exceeds 50 items.

Get the best tech tips delivered straight to your inbox.

Join thousands of readers mastering Apple, Google, Microsoft, and Linux.