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:
parent
d5aa930d34
commit
0d58ca25ab
|
|
@ -1,5 +1,5 @@
|
||||||
// public/service-worker.js
|
// public/service-worker.js
|
||||||
const CACHE_NAME = 'sociowire-v4';
|
const CACHE_NAME = 'sociowire-v5';
|
||||||
const PRECACHE = [
|
const PRECACHE = [
|
||||||
'/icons/icon-192x192.png',
|
'/icons/icon-192x192.png',
|
||||||
'/icons/icon-512x512.png',
|
'/icons/icon-512x512.png',
|
||||||
|
|
@ -26,6 +26,14 @@ self.addEventListener('activate', event => {
|
||||||
|
|
||||||
self.addEventListener('fetch', event => {
|
self.addEventListener('fetch', event => {
|
||||||
const url = new URL(event.request.url);
|
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/');
|
const isAsset = url.pathname.startsWith('/assets/');
|
||||||
if (isAsset) {
|
if (isAsset) {
|
||||||
event.respondWith(fetch(event.request));
|
event.respondWith(fetch(event.request));
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue