fix: make offline navigation and asset errors resilient

This commit is contained in:
openclaw 2026-07-28 19:14:47 +08:00
parent 73155dbbfb
commit e663f887cc
2 changed files with 16 additions and 2 deletions

View File

@ -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;
}

View File

@ -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;
}