2026-08-11 10:52:35 +02:00
|
|
|
/* Cache-first: once installed the clock never touches the network again. */
|
2026-08-11 11:18:02 +02:00
|
|
|
const CACHE = "bgclock-v2";
|
2026-08-11 10:52:35 +02:00
|
|
|
const FILES = [
|
|
|
|
|
"./",
|
|
|
|
|
"./index.html",
|
|
|
|
|
"./manifest.webmanifest",
|
|
|
|
|
"./icon-192.png",
|
|
|
|
|
"./icon-512.png",
|
|
|
|
|
"./icon-maskable-512.png"
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
self.addEventListener("install", (e) => {
|
|
|
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(FILES)).then(() => self.skipWaiting()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener("activate", (e) => {
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
caches.keys()
|
|
|
|
|
.then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k))))
|
|
|
|
|
.then(() => self.clients.claim())
|
|
|
|
|
);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener("fetch", (e) => {
|
|
|
|
|
if (e.request.method !== "GET") return;
|
|
|
|
|
e.respondWith(
|
|
|
|
|
caches.match(e.request).then((hit) => hit || fetch(e.request).then((res) => {
|
|
|
|
|
const copy = res.clone();
|
|
|
|
|
caches.open(CACHE).then((c) => c.put(e.request, copy)).catch(() => {});
|
|
|
|
|
return res;
|
|
|
|
|
}).catch(() => caches.match("./index.html")))
|
|
|
|
|
);
|
|
|
|
|
});
|