Init commit
This commit is contained in:
@@ -0,0 +1,17 @@
|
||||
/* Offline shell: network-first for navigations, cache fallback when offline. */
|
||||
const CACHE = "homelab-shell-v1";
|
||||
|
||||
self.addEventListener("install", (e) => {
|
||||
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(["/", "/index.html"])));
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (e) => {
|
||||
e.waitUntil(
|
||||
caches.keys().then((keys) => Promise.all(keys.filter((k) => k !== CACHE).map((k) => caches.delete(k)))),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (e) => {
|
||||
if (e.request.mode !== "navigate") return;
|
||||
e.respondWith(fetch(e.request).catch(() => caches.match("/index.html")));
|
||||
});
|
||||
Reference in New Issue
Block a user