This commit is contained in:
Lizandro Guarnizo
2026-01-28 14:05:01 -05:00
parent 2bf7d6c9a8
commit 3b63defba9
2 changed files with 49 additions and 10 deletions
+35 -3
View File
@@ -1,11 +1,43 @@
// Minimal service worker stub to avoid 404s during development.
// Service worker - Force no-cache for API requests
const CACHE_VERSION = 'v1.0.1';
self.addEventListener('install', (event) => {
// activate immediately
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(self.clients.claim());
event.waitUntil(
caches.keys().then(keys => {
// Clear all caches on activation
return Promise.all(keys.map(key => caches.delete(key)));
}).then(() => self.clients.claim())
);
});
self.addEventListener('fetch', (event) => {
// No-op: default network behaviour
const url = new URL(event.request.url);
// For API requests, always go to network with no-cache
if (url.pathname.startsWith('/api/') || url.pathname.includes('/api/')) {
event.respondWith(
fetch(event.request, {
cache: 'no-store',
headers: {
...Object.fromEntries(event.request.headers),
'Cache-Control': 'no-cache, no-store, must-revalidate',
'Pragma': 'no-cache'
}
}).catch(err => {
console.error('SW fetch error:', err);
return new Response(JSON.stringify({ error: 'Network error' }), {
status: 503,
headers: { 'Content-Type': 'application/json' }
});
})
);
return;
}
// For other requests, use default network behavior (no caching)
});