const VERSION='examsfit-v3.1.1';const CORE=['/','/assets/app.css?v=311','/assets/app.js?v=311','/tools','/blog','/offline'];
self.addEventListener('install',event=>event.waitUntil(caches.open(VERSION).then(cache=>cache.addAll(CORE)).then(()=>self.skipWaiting())));
self.addEventListener('activate',event=>event.waitUntil(caches.keys().then(keys=>Promise.all(keys.filter(key=>key!==VERSION).map(key=>caches.delete(key)))).then(()=>self.clients.claim())));
self.addEventListener('message',event=>{if(event.data?.type==='SAVE_URL'){const url=new URL(event.data.url,self.location.origin);if(url.origin===self.location.origin)event.waitUntil(caches.open(VERSION).then(cache=>fetch(url.href,{credentials:'same-origin'}).then(response=>{if(response.ok)return cache.put(url.href,response)})))}});
self.addEventListener('fetch',event=>{const url=new URL(event.request.url);if(event.request.method!=='GET'||url.origin!==location.origin||url.pathname.includes('/adminji')||url.pathname.includes('/admin/')||url.pathname.includes('/api/')||url.pathname.includes('/install/')||url.pathname.includes('/cron'))return;event.respondWith(fetch(event.request).then(response=>{if(!response||!response.ok||response.type!=='basic'||(response.headers.get('Cache-Control')||'').includes('no-store'))return response;const copy=response.clone();caches.open(VERSION).then(cache=>cache.put(event.request,copy));return response}).catch(()=>caches.match(event.request).then(response=>response||caches.match('/offline'))))});
