Elevate planner UX and offline resilience
This commit is contained in:
+12
-6
@@ -1,7 +1,8 @@
|
||||
const CACHE_NAME = "roast-planner-static-v3";
|
||||
const CACHE_NAME = "roast-planner-static-v4";
|
||||
const APP_SHELL = [
|
||||
"/",
|
||||
"/landing.html",
|
||||
"/app",
|
||||
"/app.css",
|
||||
"/worksheet.css",
|
||||
"/manifest.webmanifest",
|
||||
@@ -23,7 +24,6 @@ self.addEventListener("install", (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => cache.addAll(APP_SHELL)),
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
self.addEventListener("activate", (event) => {
|
||||
@@ -57,10 +57,12 @@ self.addEventListener("fetch", (event) => {
|
||||
return;
|
||||
|
||||
if (request.mode === "navigate") {
|
||||
// Never serve authenticated application HTML from cache after logout.
|
||||
event.respondWith(
|
||||
fetch(request).catch(() => caches.match("/landing.html")),
|
||||
);
|
||||
// /app is a data-free authenticated shell: draft data lives only in account-scoped
|
||||
// local storage and logout clears that namespace. This makes offline relaunch useful
|
||||
// without ever caching account data or API responses.
|
||||
event.respondWith(fetch(request).catch(() =>
|
||||
url.pathname === "/app" ? caches.match("/app") : caches.match("/landing.html"),
|
||||
));
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -78,3 +80,7 @@ self.addEventListener("fetch", (event) => {
|
||||
.catch(() => caches.match(request)),
|
||||
);
|
||||
});
|
||||
|
||||
self.addEventListener("message", (event) => {
|
||||
if (event.data === "SKIP_WAITING") self.skipWaiting();
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user