const CACHE = 'qiac-v3'; const ASSETS = [ '/qiac/', '/qiac/index.html', 'https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=DM+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap' ]; self.addEventListener('install', e => { e.waitUntil( caches.open(CACHE).then(c => c.addAll(ASSETS).catch(() => {})) ); self.skipWaiting(); }); self.addEventListener('activate', e => { e.waitUntil( caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k))) ) ); self.clients.claim(); }); self.addEventListener('fetch', e => { if (e.request.method !== 'GET') return; e.respondWith( caches.match(e.request).then(cached => { if (cached) return cached; return fetch(e.request).then(res => { if (res && res.status === 200 && res.type !== 'opaque') { const clone = res.clone(); caches.open(CACHE).then(c => c.put(e.request, clone)); } return res; }).catch(() => caches.match('/qiac/')); }) ); });