lazy-loading done
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
*/
|
||||
|
||||
// Bump this value on deploy to invalidate caches.
|
||||
const CACHE_VERSION = "v1";
|
||||
const CACHE_VERSION = "v2";
|
||||
|
||||
const CACHE_SHELL = `shell-${CACHE_VERSION}`;
|
||||
const CACHE_PAGES = `pages-${CACHE_VERSION}`;
|
||||
@@ -123,6 +123,25 @@ self.addEventListener("fetch", (event) => {
|
||||
return;
|
||||
}
|
||||
|
||||
// Network-first for global CSS to avoid serving stale styling after deploy.
|
||||
// (The SW already caches styles, but network-first prevents a "stuck" old CSS experience.)
|
||||
if (url.origin === self.location.origin && url.pathname === "/styles/global.css") {
|
||||
event.respondWith(
|
||||
(async () => {
|
||||
try {
|
||||
const fresh = await fetch(request);
|
||||
await cachePutSafe(CACHE_SHELL, request, fresh.clone());
|
||||
return fresh;
|
||||
} catch {
|
||||
const cached = await caches.match(request);
|
||||
if (cached) return cached;
|
||||
return fetch(request);
|
||||
}
|
||||
})(),
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// Stale-while-revalidate for styles/scripts/fonts from same-origin.
|
||||
if (
|
||||
url.origin === self.location.origin &&
|
||||
|
||||
Reference in New Issue
Block a user