const CACHE_VERSION = 'arrr-erp-pwa-v2-navigation-fix'; const CORE_ASSETS = [ '/manifest.webmanifest', '/static/css/theme_tokens.css', '/static/pwa/icons/icon-192.png', '/static/pwa/icons/icon-512.png' ]; self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_VERSION) .then((cache) => cache.addAll(CORE_ASSETS)) .catch(() => undefined) ); self.skipWaiting(); }); self.addEventListener('activate', (event) => { event.waitUntil( caches.keys().then((keys) => Promise.all( keys .filter((key) => key !== CACHE_VERSION) .map((key) => caches.delete(key)) )) ); self.clients.claim(); }); self.addEventListener('fetch', (event) => { const request = event.request; if (request.method !== 'GET') return; const url = new URL(request.url); if (url.origin !== self.location.origin) return; // Cache static assets only. Never substitute a CSS response for an HTML page. if (url.pathname.startsWith('/static/')) { event.respondWith( caches.match(request).then((cached) => { if (cached) return cached; return fetch(request).then((response) => { if (response && response.ok) { const copy = response.clone(); caches.open(CACHE_VERSION) .then((cache) => cache.put(request, copy)) .catch(() => undefined); } return response; }); }) ); return; } // Application pages, login, API calls and downloads remain network-first. // If the network is unavailable, return a valid HTML response instead of CSS. event.respondWith( fetch(request).catch(() => { if (request.mode === 'navigate') { return new Response( 'Offline | Audit Firm ERP

You are offline

The ERP could not reach the server. Check your internet connection and refresh this page.

', { status: 503, headers: { 'Content-Type': 'text/html; charset=utf-8', 'Cache-Control': 'no-store' } } ); } return new Response('', { status: 503, headers: { 'Cache-Control': 'no-store' } }); }) ); });