fix: guard service worker cache.put against non-http(s) schemes; correct docs to match actual nginx domain mapping
This commit is contained in:
+2
-1
@@ -24,13 +24,14 @@ self.addEventListener("fetch", (event) => {
|
||||
const url = new URL(event.request.url);
|
||||
|
||||
if (event.request.method !== "GET") return;
|
||||
if (!url.protocol.startsWith("http")) return;
|
||||
if (url.pathname.startsWith("/api")) return;
|
||||
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((res) => {
|
||||
const resClone = res.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, resClone));
|
||||
caches.open(CACHE_NAME).then((cache) => cache.put(event.request, resClone).catch(() => {}));
|
||||
return res;
|
||||
})
|
||||
.catch(() => caches.match(event.request))
|
||||
|
||||
Reference in New Issue
Block a user