Fix PWA installation support
This commit is contained in:
1 parent
bbdfe97c4e
commit
153f184c38
7 files changed
+41
-7
No files matched your search
+11
-4
@@ -1,10 +1,17 @@
|
||||
const CACHE = "cet6-shell-v1";
|
||||
const APP_SHELL = ["/", "/tasks", "/stats", "/review", "/manifest.webmanifest", "/favicon.svg"];
|
||||
const CACHE = "cet6-shell-v2";
|
||||
const APP_SHELL = ["/", "/manifest.webmanifest", "/favicon.svg", "/icon-192.png", "/icon-512.png"];
|
||||
self.addEventListener("install", event => event.waitUntil(caches.open(CACHE).then(cache => cache.addAll(APP_SHELL)).then(() => self.skipWaiting())));
|
||||
self.addEventListener("activate", event => event.waitUntil(self.clients.claim()));
|
||||
self.addEventListener("activate", event => event.waitUntil(
|
||||
caches.keys().then(keys => Promise.all(keys.filter(key => key !== CACHE).map(key => caches.delete(key)))).then(() => self.clients.claim())
|
||||
));
|
||||
self.addEventListener("fetch", event => {
|
||||
const request = event.request;
|
||||
if (request.method !== "GET" || new URL(request.url).origin !== location.origin) return;
|
||||
if (request.url.includes("/api/")) return;
|
||||
event.respondWith(fetch(request).then(response => { const copy = response.clone(); caches.open(CACHE).then(cache => cache.put(request, copy)); return response; }).catch(() => caches.match(request).then(found => found || caches.match("/"))));
|
||||
event.respondWith(fetch(request).then(response => {
|
||||
if (response.ok && new URL(request.url).pathname.startsWith("/_next/")) {
|
||||
const copy = response.clone(); caches.open(CACHE).then(cache => cache.put(request, copy));
|
||||
}
|
||||
return response;
|
||||
}).catch(() => caches.match(request).then(found => found || caches.match("/"))));
|
||||
});
|
||||
Reference in new issue
Block a user