2026-03-29 12:25:42 +00:00
|
|
|
|
const CACHE = 'posimai-brief-v5';
|
2026-03-21 04:37:40 +00:00
|
|
|
|
const ASSETS = ['/', '/index.html', '/manifest.json'];
|
|
|
|
|
|
const ORIGIN = self.location.origin;
|
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', e => {
|
|
|
|
|
|
e.waitUntil(caches.open(CACHE).then(c => c.addAll(ASSETS)));
|
|
|
|
|
|
self.skipWaiting();
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener('activate', e => {
|
|
|
|
|
|
e.waitUntil(
|
|
|
|
|
|
caches.keys().then(keys =>
|
|
|
|
|
|
Promise.all(keys.filter(k => k !== CACHE).map(k => caches.delete(k)))
|
2026-03-29 12:25:42 +00:00
|
|
|
|
).then(() => self.clients.claim())
|
|
|
|
|
|
.catch(err => console.warn('[SW] activate error', err))
|
2026-03-21 04:37:40 +00:00
|
|
|
|
);
|
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
self.addEventListener('fetch', e => {
|
|
|
|
|
|
// クロスオリジン(Feed API・server.js・open-meteo 等)はキャッシュしない
|
|
|
|
|
|
if (!e.request.url.startsWith(ORIGIN)) return;
|
|
|
|
|
|
e.respondWith(
|
|
|
|
|
|
caches.match(e.request).then(cached => cached || fetch(e.request))
|
|
|
|
|
|
);
|
|
|
|
|
|
});
|