Fix service worker caching API responses

The service worker was using cache-first strategy for ALL requests
including API calls, causing stale data to be served indefinitely.

Now API routes (/api/*, /ws) are always fetched fresh.

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
SocioWire 2026-01-04 07:47:14 +00:00
parent d5aa930d34
commit 0d58ca25ab
1 changed files with 9 additions and 1 deletions

View File

@ -1,5 +1,5 @@
// public/service-worker.js
const CACHE_NAME = 'sociowire-v4';
const CACHE_NAME = 'sociowire-v5';
const PRECACHE = [
'/icons/icon-192x192.png',
'/icons/icon-512x512.png',
@ -26,6 +26,14 @@ self.addEventListener('activate', event => {
self.addEventListener('fetch', event => {
const url = new URL(event.request.url);
// Never cache API calls - always fetch fresh data
const isAPI = url.pathname.startsWith('/api/') || url.pathname.startsWith('/ws');
if (isAPI) {
event.respondWith(fetch(event.request));
return;
}
const isAsset = url.pathname.startsWith('/assets/');
if (isAsset) {
event.respondWith(fetch(event.request));