Precache Update Flow
You'll learn how service workers detect and apply precache updates, and what happens to old cached assets during the update process.
When you update your site and deploy new static assets, Workbox (or your manual precache logic) generates a fresh precache manifest with updated revision hashes. Here's how the browser recognizes and handles that change:
How Updates Are Detected
During the service worker's 24-hour update check (or when manually triggered), the browser compares the new service worker file byte-by-byte with the installed version. If the precache manifest has changed—even one file's hash is different—the browser treats this as a new service worker and enters the installing state.
The Update Dance
- Install phase: The new service worker downloads and caches all updated assets into a new cache (often named with a different version key like
precache-v2) - Waiting phase: The new worker waits in the background while the old one still controls pages
- Activation phase: Once all tabs close (or
skipWaiting()is called), the new service worker activates and runs cleanup
Cleaning Up Old Caches
During activation, your service worker should delete obsolete caches. Workbox handles this automatically—it compares cache names and removes any that don't match the current precache version. This prevents your app from accumulating stale caches indefinitely.
Think of it like moving apartments: You pack new belongings into the new place (install), wait until you're ready to move out (waiting), then throw away boxes from the old apartment (activation cleanup).
Key Takeaway: Precache updates trigger a full service worker lifecycle, installing new assets into fresh caches and cleaning up old versions during activation to prevent storage bloat.