Course contentsShow
← Web Development
Lesson 2422 of 2,98243. Service Workers Deep DiveFree lesson

Cache Size Limitations

Learn about storage quotas, how precaching affects initial install size, and runtime cache eviction policies.

Cache Size Limitations

You'll learn how browser storage quotas, precache size, and cache eviction policies constrain your service worker caching strategy.

The Storage Reality

Unlike server-side storage where you control capacity, browser caches live under strict quotas. Each browser allocates a limited amount of disk space for your origin's data (Cache API, IndexedDB, LocalStorage combined), typically a percentage of available disk space (often 10-50% of free space, with per-origin limits around 20-60% of that pool).

Think of it like a hotel with limited rooms: you can't keep every guest forever, and when space runs tight, some have to check out.

Precaching and Initial Install Size

When your service worker precaches assets during installation, those files count against your quota immediately. A bloated precache manifest (loading hundreds of large images or videos) can:

  • Fail the install if it exceeds quota mid-download
  • Make first-time installation slow and bandwidth-heavy
  • Leave less room for runtime caching

Best practice: Precache only critical shell assets (HTML, core CSS/JS, essential icons). Let runtime caching handle everything else on-demand.

Runtime Cache Eviction Policies

When quota fills up, browsers use LRU (Least Recently Used) eviction:

  • Least-accessed caches disappear first
  • Individual cache entries within a cache may be removed
  • No warning to your service worker—data just vanishes

Your defense: Implement cache size limits and expiration policies (as covered in earlier lessons). Manually delete old entries before the browser does it unpredictably. Prioritize which caches are "best-effort" vs. critical.

Checking Available Quota

Use the StorageManager API (if needed in future builds):

// Concept illustration only - you'd check quota availability
// to decide whether aggressive caching is safe

Key Takeaway: Browser storage is finite and shared; design cache strategies that stay within quotas by limiting precache size, setting expiration policies, and accepting that runtime caches are disposable.