diff --git a/frontend/nginx.conf b/frontend/nginx.conf index 032258a..995969b 100644 --- a/frontend/nginx.conf +++ b/frontend/nginx.conf @@ -17,8 +17,23 @@ server { application/javascript application/json image/svg+xml; - # ── PWA : cache long sur les assets hasheés ─────────────── - location ~* \.(js|css|woff2?|png|svg|ico|webmanifest)$ { + # ── Service Worker — jamais mis en cache (sinon l'ancien SW tourne après déploiement) + location = /sw.js { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + add_header Pragma "no-cache"; + expires 0; + try_files $uri =404; + } + + # ── Manifeste PWA — pas de cache long (doit se mettre à jour) + location ~* \.webmanifest$ { + add_header Cache-Control "no-cache, no-store, must-revalidate"; + expires 0; + try_files $uri =404; + } + + # ── PWA : cache long sur les assets hashés par Vite ────────── + location ~* \.(js|css|woff2?|png|svg|ico)$ { expires 1y; add_header Cache-Control "public, immutable"; try_files $uri =404; @@ -27,7 +42,7 @@ server { # ── API → backend (service Docker interne) ──────────────── location /api/ { set $upstream_backend http://notesfrais-backend:3001; - proxy_pass $upstream_backend/api/; + proxy_pass $upstream_backend; proxy_http_version 1.1; proxy_set_header Host $host; diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts index 5ef0d6c..e2fe5bc 100644 --- a/frontend/vite.config.ts +++ b/frontend/vite.config.ts @@ -26,13 +26,15 @@ export default defineConfig({ }, workbox: { globPatterns: ['**/*.{js,css,html,ico,png,svg,woff2}'], + cleanupOutdatedCaches: true, runtimeCaching: [ { - // Cache API responses (stale-while-revalidate pour les listes) + // Network-first pour les listes (évite de servir un cache vide) urlPattern: /^\/api\/(?:companies|categories)/, - handler: 'StaleWhileRevalidate', + handler: 'NetworkFirst', options: { - cacheName: 'api-static', + cacheName: 'notesfrais-api-static', + networkTimeoutSeconds: 8, expiration: { maxEntries: 20, maxAgeSeconds: 60 * 60 }, }, }, @@ -41,7 +43,7 @@ export default defineConfig({ urlPattern: /^\/api\/invoices/, handler: 'NetworkFirst', options: { - cacheName: 'api-invoices', + cacheName: 'notesfrais-api-invoices', networkTimeoutSeconds: 8, expiration: { maxEntries: 100, maxAgeSeconds: 24 * 60 * 60 }, },