diff --git a/src/sw.js b/src/sw.js index f745338f3752..bcf17143925b 100644 --- a/src/sw.js +++ b/src/sw.js @@ -12,7 +12,6 @@ import { NetworkOnly, StaleWhileRevalidate, } from "workbox-strategies"; -/* eslint-enable import/no-extraneous-dependencies */ const cacheName = cacheNames.runtime; @@ -25,16 +24,23 @@ const otherManifest = [ url: "/app-shell/index.html", }, ]; -const manifestURLs = [...manifest, ...otherManifest].map((entry) => { - const url = new URL(entry.url, self.location); - return url.href; -}); +const manifestURLs = [ + ...new Set( + [...manifest, ...otherManifest].map((entry) => { + const url = new URL(entry.url, self.location); + return url.href; + }), + ), +]; self.addEventListener("install", (event) => { event.waitUntil( - caches.open(cacheName).then((cache) => cache.addAll(manifestURLs)), + (async () => { + const cache = await caches.open(cacheName); + + await Promise.allSettled(manifestURLs.map((url) => cache.add(url))); + })(), ); }); - self.addEventListener("activate", (event) => { // - [x] clean up outdated runtime cache event.waitUntil( @@ -52,7 +58,6 @@ self.addEventListener("activate", (event) => { ), ); }); - registerRoute( ({ url }) => manifestURLs.includes(url.href), new NetworkFirst({