fix: make offline navigation and asset errors resilient
This commit is contained in:
parent
73155dbbfb
commit
e663f887cc
|
|
@ -14,6 +14,20 @@ server {
|
|||
proxy_set_header X-Forwarded-Proto $scheme;
|
||||
}
|
||||
|
||||
location = /sw.js {
|
||||
add_header Cache-Control "no-cache";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location = /index.html {
|
||||
add_header Cache-Control "no-cache";
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location ~* ^/assets/.*\.(?:js|css)$ {
|
||||
try_files $uri =404;
|
||||
}
|
||||
|
||||
location / {
|
||||
try_files $uri $uri/ /index.html;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -99,7 +99,7 @@ function offlineServiceWorkerPlugin(): Plugin {
|
|||
const bundledAssets = Object.keys(bundle)
|
||||
.filter((fileName) => fileName !== "sw.js")
|
||||
.map((fileName) => `/${fileName}`);
|
||||
const precache = [...new Set([...bundledAssets, ...publicAssets])];
|
||||
const precache = [...new Set(["/", ...bundledAssets, ...publicAssets])];
|
||||
const source = `const CACHE_NAME = "cents-shell-v4";
|
||||
const PRECACHE = ${JSON.stringify(precache, null, 2)};
|
||||
|
||||
|
|
@ -126,7 +126,7 @@ self.addEventListener("fetch", (event) => {
|
|||
const copy = response.clone();
|
||||
void caches.open(CACHE_NAME).then((cache) => cache.put("/", copy));
|
||||
return response;
|
||||
}).catch(() => caches.match("/")),
|
||||
}).catch(async () => (await caches.match("/")) ?? caches.match("/index.html")),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue