-
Notifications
You must be signed in to change notification settings - Fork 7
Open
Description
in the section cache smarter, the function cacheVersioned() is intended to cache assets that may change over time.
async function cacheVersioned(version, assets) {
const exists = await caches.has(`version-${version}`);
if (!exists) {
const requests = assets.map(asset => new Request(asset));
const preCachedResponses =
await Promise.all(requests.map(req => caches.match(req)));
const cache = await caches.open(`version-${version}`);
return Promise.all(requests.map((request, idx) => {
return preCachedResponses[idx]
? cache.put(request, preCachedResponses[idx].clone())
: cache.add(request);
}));
}
}But, AFAIK, the code will fail to do so. The function only checks if a Response already exists, not the content of the response (since that is impossible).
The technique will only work if the URL itself changes (hashes?).
Metadata
Metadata
Assignees
Labels
No labels