notify the user when a new service worker gets installed

This commit is contained in:
m5r
2022-06-06 00:34:50 +02:00
parent 0cb999d260
commit 1425a72d39
5 changed files with 65 additions and 3 deletions

View File

@ -10,5 +10,5 @@ export default async function handleActivate(event: ExtendableEvent) {
await self.registration.navigationPreload.enable();
}
await deleteCaches();
await deleteCaches(); // TODO: maybe wait for the user to reload before busting the cache
}

View File

@ -27,7 +27,7 @@ export function cacheAsset(event: FetchEvent): Promise<Response> {
ignoreSearch: true,
})
.then((cachedResponse) => {
console.debug(`Serving asset from ${cachedResponse ? "cache" : " network"}`, url.pathname);
console.debug(`Serving asset from ${cachedResponse ? "cache" : "network"}`, url.pathname);
const fetchPromise = event.preloadResponse
.then((preloadedResponse?: Response) => preloadedResponse || fetch(event.request.clone()))
@ -253,7 +253,7 @@ export function cacheDocument(event: FetchEvent): Promise<Response> {
}
export async function deleteCaches() {
console.debug("Caches deleted");
const allCaches = await caches.keys();
await Promise.all(allCaches.map((cacheName) => caches.delete(cacheName)));
console.debug("Caches deleted");
}