allow updating cache of unhashed assets (like config) in service worker

This commit is contained in:
Bruno Windels 2022-05-18 21:41:47 +02:00
parent 1555b0f4bc
commit 13428bd03c

View file

@ -160,8 +160,14 @@ async function updateCache(request, response) {
cache.put(request, response.clone()); cache.put(request, response.clone());
} else if (request.url.startsWith(baseURL)) { } else if (request.url.startsWith(baseURL)) {
let assetName = request.url.substr(baseURL.length); let assetName = request.url.substr(baseURL.length);
let cacheName;
if (HASHED_CACHED_ON_REQUEST_ASSETS.includes(assetName)) { if (HASHED_CACHED_ON_REQUEST_ASSETS.includes(assetName)) {
const cache = await caches.open(hashedCacheName); cacheName = hashedCacheName;
} else if (UNHASHED_PRECACHED_ASSETS.includes(assetName)) {
cacheName = unhashedCacheName;
}
if (cacheName) {
const cache = await caches.open(cacheName);
await cache.put(request, response.clone()); await cache.put(request, response.clone());
} }
} }