fix: Replace contaminated wolfpack-kiosk service worker with Veridian sw
This commit is contained in:
parent
1f7f722238
commit
bf2fbe9b19
1 changed files with 8 additions and 35 deletions
|
|
@ -1,55 +1,28 @@
|
|||
const CACHE_NAME = 'wolfpack-kiosk-v1';
|
||||
const CACHE_NAME = 'veridian-v2';
|
||||
const STATIC_ASSETS = [
|
||||
'/kiosk',
|
||||
'/badges',
|
||||
'/',
|
||||
'/manifest.json'
|
||||
];
|
||||
|
||||
// Install event - cache static assets
|
||||
// Install event - skip waiting immediately to invalidate old cache
|
||||
self.addEventListener('install', (event) => {
|
||||
event.waitUntil(
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
return cache.addAll(STATIC_ASSETS);
|
||||
})
|
||||
);
|
||||
self.skipWaiting();
|
||||
});
|
||||
|
||||
// Activate event - clean up old caches
|
||||
// Activate event - clean up ALL old caches
|
||||
self.addEventListener('activate', (event) => {
|
||||
event.waitUntil(
|
||||
caches.keys().then((cacheNames) => {
|
||||
return Promise.all(
|
||||
cacheNames
|
||||
.filter((name) => name !== CACHE_NAME)
|
||||
.map((name) => caches.delete(name))
|
||||
cacheNames.map((name) => caches.delete(name))
|
||||
);
|
||||
})
|
||||
);
|
||||
self.clients.claim();
|
||||
});
|
||||
|
||||
// Fetch event - network first, falling back to cache
|
||||
// Fetch event - network only, no caching (to prevent stale assets)
|
||||
self.addEventListener('fetch', (event) => {
|
||||
// Skip non-GET requests
|
||||
if (event.request.method !== 'GET') return;
|
||||
|
||||
// Skip API requests (always fetch from network)
|
||||
if (event.request.url.includes('/api/')) return;
|
||||
|
||||
event.respondWith(
|
||||
fetch(event.request)
|
||||
.then((response) => {
|
||||
// Clone and cache the response
|
||||
const responseClone = response.clone();
|
||||
caches.open(CACHE_NAME).then((cache) => {
|
||||
cache.put(event.request, responseClone);
|
||||
});
|
||||
return response;
|
||||
})
|
||||
.catch(() => {
|
||||
// Network failed, try cache
|
||||
return caches.match(event.request);
|
||||
})
|
||||
);
|
||||
// Just pass through to network
|
||||
return;
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue