Skip to content

Commit 6ae199c

Browse files
committed
tolerate precache failures
1 parent c3ea600 commit 6ae199c

File tree

1 file changed

+3
-16
lines changed

1 file changed

+3
-16
lines changed

src/sw.js

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,31 +25,18 @@ const otherManifest = [
2525
url: "/app-shell/index.html",
2626
},
2727
];
28-
const EXCLUDED_PRECACHE_URLS = new Set([
29-
new URL("/icon_512x512.png", self.location).href,
30-
]);
3128

3229
const allManifestURLs = [...manifest, ...otherManifest].map(
3330
(entry) => new URL(entry.url, self.location).href,
3431
);
35-
const requiredManifestURLs = allManifestURLs.filter(
36-
(href) => !EXCLUDED_PRECACHE_URLS.has(href),
37-
);
38-
39-
const optionalManifestURLs = [...EXCLUDED_PRECACHE_URLS];
4032

4133
self.addEventListener("install", (event) => {
4234
event.waitUntil(
4335
(async () => {
4436
const cache = await caches.open(cacheName);
4537

46-
// Fail install only if "required" assets fail
47-
await cache.addAll(requiredManifestURLs);
48-
4938
// Optional assets: don't fail SW install if these fail
50-
await Promise.allSettled(
51-
optionalManifestURLs.map((url) => cache.add(url)),
52-
);
39+
await Promise.allSettled(allManifestURLs.map((url) => cache.add(url)));
5340
})(),
5441
);
5542
});
@@ -60,15 +47,15 @@ self.addEventListener("activate", (event) => {
6047
// clean up those who are not listed in manifestURLs
6148
const keys = await cache.keys();
6249
for (const request of keys) {
63-
if (!requiredManifestURLs.includes(request.url)) {
50+
if (!allManifestURLs.includes(request.url)) {
6451
await cache.delete(request);
6552
}
6653
}
6754
})(),
6855
);
6956
});
7057
registerRoute(
71-
({ url }) => requiredManifestURLs.includes(url.href),
58+
({ url }) => allManifestURLs.includes(url.href),
7259
new NetworkFirst({
7360
cacheName,
7461
}),

0 commit comments

Comments
 (0)