2026-04-05 05:20:25 +00:00
|
|
|
const CACHE = 'posimai-store-v2';
|
2026-03-31 23:11:15 +00:00
|
|
|
const STATIC = ['/', '/index.html', '/manifest.json', '/logo.png'];
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', e => {
|
|
|
|
|
e.waitUntil(caches.open(CACHE).then(c => c.addAll(STATIC)).then(() => self.skipWaiting()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', e => {
|
|
|
|
|
e.waitUntil(caches.keys().then(keys => Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))).then(() => self.clients.claim()));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
self.addEventListener('fetch', e => {
|
|
|
|
|
if (e.request.method !== 'GET') return;
|
|
|
|
|
if (new URL(e.request.url).origin !== location.origin) return;
|
|
|
|
|
e.respondWith(
|
|
|
|
|
caches.match(e.request).then(cached => cached || fetch(e.request).then(res => {
|
|
|
|
|
const clone = res.clone();
|
|
|
|
|
caches.open(CACHE).then(c => c.put(e.request, clone));
|
|
|
|
|
return res;
|
|
|
|
|
}))
|
|
|
|
|
);
|
|
|
|
|
});
|