feat(kanban): restore commands offline
req: local/001\nreq: local/002\nreq: local/003\nreq: local/004
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
const CACHE = "hemx-kanban-shell-v1";
|
||||
const SHELL = [
|
||||
"/",
|
||||
"/hemx.js",
|
||||
"/hemx.client.js",
|
||||
"/kanban_client.js",
|
||||
"/kanban_client_bg.wasm",
|
||||
"/app.js",
|
||||
];
|
||||
|
||||
self.addEventListener("install", (event) => {
|
||||
event.waitUntil(caches.open(CACHE).then((cache) => cache.addAll(SHELL)).then(() => self.skipWaiting()));
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys()
|
||||
.then((names) => Promise.all(names.filter((name) => name.startsWith("hemx-kanban-shell-") && name !== CACHE).map((name) => caches.delete(name))))
|
||||
.then(() => self.clients.claim()),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("fetch", (event) => {
|
||||
if (event.request.method !== "GET") return;
|
||||
const url = new URL(event.request.url);
|
||||
if (url.origin !== self.location.origin || !SHELL.includes(url.pathname)) return;
|
||||
event.respondWith(
|
||||
caches.match(event.request, { ignoreSearch: true }).then((cached) => cached || fetch(event.request)),
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user