Perf: Prioritäts-Seiten pre-cache + Stale-While-Revalidate + Background-Warm-up (SW by-v981)
This commit is contained in:
parent
78f3077317
commit
1a8716b0b2
3 changed files with 48 additions and 8 deletions
|
|
@ -3,16 +3,28 @@
|
|||
Offline-Cache + Push Notifications + Tile-Cache
|
||||
============================================================ */
|
||||
|
||||
const CACHE_VERSION = 'by-v980';
|
||||
const CACHE_VERSION = 'by-v981';
|
||||
const CACHE_STATIC = `${CACHE_VERSION}-static`;
|
||||
const CACHE_TILES = 'ban-yaro-tiles-v1'; // bleibt über SW-Updates erhalten
|
||||
const CACHE_API = 'ban-yaro-api-v1'; // API-Response-Cache
|
||||
|
||||
// Prioritäts-Seiten: werden pre-gecacht + Stale-While-Revalidate
|
||||
const PRIORITY_PAGES = [
|
||||
'/js/pages/admin.js',
|
||||
'/js/pages/erste-hilfe.js',
|
||||
'/js/pages/diary.js',
|
||||
'/js/pages/map.js',
|
||||
'/js/pages/walks.js',
|
||||
'/js/pages/routes.js',
|
||||
'/js/pages/poison.js',
|
||||
'/js/pages/lost.js',
|
||||
];
|
||||
|
||||
// index.html wird NICHT pre-gecacht (immer Network-First)
|
||||
const STATIC_ASSETS = [
|
||||
'/css/design-system.css?v=700',
|
||||
'/css/layout.css?v=700',
|
||||
'/css/components.css?v=700',
|
||||
'/css/design-system.css?v=980',
|
||||
'/css/layout.css?v=980',
|
||||
'/css/components.css?v=980',
|
||||
'/icons/phosphor.svg',
|
||||
'/js/api.js',
|
||||
'/js/ui.js',
|
||||
|
|
@ -22,6 +34,7 @@ const STATIC_ASSETS = [
|
|||
'/css/MarkerCluster.Default.css',
|
||||
'/manifest.json',
|
||||
'/icons/icon-192.png',
|
||||
...PRIORITY_PAGES,
|
||||
];
|
||||
|
||||
// ----------------------------------------------------------
|
||||
|
|
@ -297,7 +310,21 @@ self.addEventListener('fetch', event => {
|
|||
return;
|
||||
}
|
||||
|
||||
// CSS, Core-JS + Seiten-Module: immer Network-First — damit iOS nie veraltete Versionen cached
|
||||
// Prioritäts-Seiten: Stale-While-Revalidate — sofort aus Cache, im Hintergrund aktualisieren
|
||||
if (PRIORITY_PAGES.includes(url.pathname)) {
|
||||
event.respondWith(
|
||||
caches.open(CACHE_STATIC).then(async cache => {
|
||||
const cached = await cache.match(event.request, { ignoreSearch: true });
|
||||
const netFetch = fetch(event.request)
|
||||
.then(res => { if (res.ok) cache.put(event.request, res.clone()); return res; })
|
||||
.catch(() => null);
|
||||
return cached ?? (await netFetch) ?? new Response('', { status: 503 });
|
||||
})
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
// CSS, Core-JS + übrige Seiten-Module: Network-First — damit iOS nie veraltete Versionen cached
|
||||
if (url.pathname.startsWith('/css/') || url.pathname.startsWith('/js/pages/')
|
||||
|| url.pathname.startsWith('/js/app.js') || url.pathname.startsWith('/js/ui.js')
|
||||
|| url.pathname.startsWith('/js/api.js') || url.pathname.startsWith('/js/worlds.js')) {
|
||||
|
|
@ -310,7 +337,7 @@ self.addEventListener('fetch', event => {
|
|||
}
|
||||
return response;
|
||||
})
|
||||
.catch(() => caches.match(event.request)
|
||||
.catch(() => caches.match(event.request, { ignoreSearch: true })
|
||||
.then(cached => cached || new Response('', { status: 503 })))
|
||||
);
|
||||
return;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue