fix(webui): harden PWA service worker caching and registration
- Exclude /webui/* endpoints from the service worker cache; the /webui/bootstrap endpoint issues fresh gateway credentials on every load and must never be cached or replayed offline. - Restrict cache-first handling to hashed /assets/ files (served immutable). Un-hashed brand icons and the favicon stay network-first so future icon swaps reach installed clients. - Prune stale hashed assets whenever the app shell refreshes, so old build assets cannot accumulate even when sw.js itself is unchanged. - Serve the cached app shell for offline deep-link navigations. - Ignore service worker registration failures; add unit tests for the service worker and the main-entry registration.
This commit is contained in:
+8
-3
@@ -31,8 +31,13 @@ ReactDOM.createRoot(root).render(<App />);
|
||||
|
||||
if ("serviceWorker" in navigator) {
|
||||
window.addEventListener("load", () => {
|
||||
navigator.serviceWorker.register("/sw.js", {
|
||||
updateViaCache: "none",
|
||||
});
|
||||
navigator.serviceWorker
|
||||
.register("/sw.js", {
|
||||
updateViaCache: "none",
|
||||
})
|
||||
.catch(() => {
|
||||
// Service workers are progressive enhancement; registration failures
|
||||
// (unsupported proxies, blocked storage) must not break the app.
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user