breakout71/src/PWA/sw-b71.js

46 lines
1 KiB
JavaScript
Raw Normal View History

2025-03-14 20:12:02 +01:00
// The version of the cache.
2025-04-09 11:40:16 +02:00
const VERSION = "29069860";
2025-03-14 20:12:02 +01:00
// The name of the cache
const CACHE_NAME = `breakout-71-${VERSION}`;
// The static resources that the app needs to function.
const APP_STATIC_RESOURCES = ["/"];
2025-03-14 20:12:02 +01:00
// On install, cache the static resources
self.addEventListener("install", (event) => {
event.waitUntil(
(async () => {
const cache = await caches.open(CACHE_NAME);
2025-03-19 14:31:14 +01:00
await cache.addAll(APP_STATIC_RESOURCES);
2025-03-14 20:12:02 +01:00
})(),
);
});
// delete old caches on activate
self.addEventListener("activate", (event) => {
event.waitUntil(
(async () => {
const names = await caches.keys();
await Promise.all(
names.map((name) => {
if (name !== CACHE_NAME) {
return caches.delete(name);
}
}),
);
await clients.claim();
})(),
);
});
self.addEventListener("fetch", (event) => {
if (
event.request.mode === "navigate" &&
event.request.url.endsWith("/index.html?isPWA=true")
) {
2025-03-14 20:12:02 +01:00
event.respondWith(caches.match("/"));
return;
}
});