From 0d58ca25ab933d1fa7adcd4d8c65ef9346b2b2fd Mon Sep 17 00:00:00 2001 From: SocioWire Date: Sun, 4 Jan 2026 07:47:14 +0000 Subject: [PATCH] Fix service worker caching API responses MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- public/service-worker.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/public/service-worker.js b/public/service-worker.js index 9398ea6..eb9bd33 100644 --- a/public/service-worker.js +++ b/public/service-worker.js @@ -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));