The Precache Manifest
You'll learn how the precache manifest acts as a blueprint for your service worker, defining exactly which files to cache and how to track changes.
When you use Workbox (or build tools that generate service workers), a precache manifest is created—essentially a JSON array listing all the files you want cached immediately when your service worker installs. But it's more than just a file list; each entry includes crucial metadata.
What's Inside a Precache Manifest
A typical manifest entry looks like this:
[
{
url: '/styles/main.css',
revision: 'a3f4b2c1'
},
{
url: '/js/app.js',
revision: '7d8e9f0a'
},
{
url: '/index.html',
revision: null // URL contains hash already
}
]
Revision Hashing: The Version Fingerprint
The revision field is a hash of the file's contents. Think of it like a fingerprint—if even one character changes in your CSS file, the hash changes completely. This tells the service worker: "This is a different version; re-cache it."
Some files include hashes in their URLs (like app.7d8e9f0a.js). For these, revision can be null because the URL itself acts as the version identifier.
Why Versioning Matters
Without revision tracking, your service worker wouldn't know when main.css has been updated. Users might see stale, cached versions indefinitely. The manifest's versioning ensures that when your build process generates a new hash, the service worker detects the change during its update check and refreshes only the modified files—not everything.
This approach is far more efficient than cache-busting entire cache stores or forcing users to hard-refresh.
Key Takeaway: The precache manifest is a versioned inventory of critical assets, using revision hashes to detect changes and ensure users always receive updated files without manual cache clearing.