sumbloom / sw.js
CyberMax
Deploy sumbloom
96a4f6b verified
Raw History Blame
1.17 kB
/* Sumbloom offline cache. © 2026 CyberMax. All rights reserved. */
var CACHE = "sumbloom-v1";
var FILES = ["./", "index.html", "style.css", "puzzle.js", "game.js", "manifest.webmanifest", "icon.svg", "icon-192.png", "icon-512.png"];
self.addEventListener("install", function (e) {
e.waitUntil(caches.open(CACHE).then(function (c) { return c.addAll(FILES); }).then(function () { return self.skipWaiting(); }));
});
self.addEventListener("activate", function (e) {
e.waitUntil(caches.keys().then(function (keys) {
return Promise.all(keys.filter(function (k) { return k !== CACHE; }).map(function (k) { return caches.delete(k); }));
}).then(function () { return self.clients.claim(); }));
});
self.addEventListener("fetch", function (e) {
if (e.request.method !== "GET" || new URL(e.request.url).origin !== location.origin) return;
// Network first so updates arrive quickly; cache as offline fallback.
e.respondWith(fetch(e.request).then(function (r) {
var copy = r.clone();
caches.open(CACHE).then(function (c) { c.put(e.request, copy); });
return r;
}).catch(function () { return caches.match(e.request, { ignoreSearch: true }); }));
});