fix(pwa): serve the manifest network-first so changed app colours reach the browser
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m24s
MindSift CI & Docker Release / Build, Test in Container & Push (push) Successful in 1m24s
chore(release): v0.14.2 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
61541b2851
commit
08ae91fcdb
4 files changed
+27
-6
No files matched your search
+17
-2
@@ -2,10 +2,12 @@
|
||||
// - Page loads (navigation): network first, so a new release is picked up right away; offline the
|
||||
// last loaded index.html is used.
|
||||
// - Built bundles (/assets/*, file names contain a content hash): from the cache, loaded once.
|
||||
// - Icons and manifest: from the cache, refreshed in the background.
|
||||
// - Icons: from the cache, refreshed in the background.
|
||||
// - Manifest: network first (the browser checks it for changed app colours and name; a cached copy
|
||||
// would hand it the old values), the cache only offline.
|
||||
// - API requests are never touched; offline data comes from the app's own cache (lib/offline.ts).
|
||||
// Raise VERSION when this file changes in a way that needs fresh caches.
|
||||
const VERSION = 'v3';
|
||||
const VERSION = 'v4';
|
||||
const SHELL_CACHE = `mindsift-shell-${VERSION}`;
|
||||
const ASSET_CACHE = `mindsift-assets-${VERSION}`;
|
||||
const MAX_ASSETS = 80;
|
||||
@@ -70,6 +72,17 @@ async function cacheFirstAsset(request) {
|
||||
return response;
|
||||
}
|
||||
|
||||
async function networkFirstShell(request) {
|
||||
const cache = await caches.open(SHELL_CACHE);
|
||||
try {
|
||||
const response = await fetch(request, { cache: 'no-store' });
|
||||
if (response.ok && response.type === 'basic') cache.put(request, response.clone());
|
||||
return response;
|
||||
} catch {
|
||||
return (await cache.match(request)) || Response.error();
|
||||
}
|
||||
}
|
||||
|
||||
async function staleWhileRevalidate(request) {
|
||||
const cache = await caches.open(SHELL_CACHE);
|
||||
const hit = await cache.match(request);
|
||||
@@ -162,6 +175,8 @@ self.addEventListener('fetch', (event) => {
|
||||
event.respondWith(networkFirstPage(request));
|
||||
} else if (url.pathname.startsWith('/assets/')) {
|
||||
event.respondWith(cacheFirstAsset(request));
|
||||
} else if (url.pathname === '/manifest.json') {
|
||||
event.respondWith(networkFirstShell(request));
|
||||
} else if (SHELL_URLS.includes(url.pathname)) {
|
||||
event.respondWith(staleWhileRevalidate(request));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user