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;
|
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 / {
|
location / {
|
||||||
try_files $uri $uri/ /index.html;
|
try_files $uri $uri/ /index.html;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -99,7 +99,7 @@ function offlineServiceWorkerPlugin(): Plugin {
|
||||||
const bundledAssets = Object.keys(bundle)
|
const bundledAssets = Object.keys(bundle)
|
||||||
.filter((fileName) => fileName !== "sw.js")
|
.filter((fileName) => fileName !== "sw.js")
|
||||||
.map((fileName) => `/${fileName}`);
|
.map((fileName) => `/${fileName}`);
|
||||||
const precache = [...new Set([...bundledAssets, ...publicAssets])];
|
const precache = [...new Set(["/", ...bundledAssets, ...publicAssets])];
|
||||||
const source = `const CACHE_NAME = "cents-shell-v4";
|
const source = `const CACHE_NAME = "cents-shell-v4";
|
||||||
const PRECACHE = ${JSON.stringify(precache, null, 2)};
|
const PRECACHE = ${JSON.stringify(precache, null, 2)};
|
||||||
|
|
||||||
|
|
@ -126,7 +126,7 @@ self.addEventListener("fetch", (event) => {
|
||||||
const copy = response.clone();
|
const copy = response.clone();
|
||||||
void caches.open(CACHE_NAME).then((cache) => cache.put("/", copy));
|
void caches.open(CACHE_NAME).then((cache) => cache.put("/", copy));
|
||||||
return response;
|
return response;
|
||||||
}).catch(() => caches.match("/")),
|
}).catch(async () => (await caches.match("/")) ?? caches.match("/index.html")),
|
||||||
);
|
);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue