2026-03-30 14:23:28 +00:00
|
|
|
const CACHE = 'posimai-dev-v1';
|
|
|
|
|
const SHELL = ['/'];
|
|
|
|
|
|
|
|
|
|
self.addEventListener('install', (e) => {
|
|
|
|
|
e.waitUntil(caches.open(CACHE).then((c) => c.addAll(SHELL)));
|
|
|
|
|
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();
|
|
|
|
|
});
|
|
|
|
|
|
2026-04-24 07:44:01 +00:00
|
|
|
// WebSocket・API レスポンスはキャッシュしない
|
2026-03-30 14:23:28 +00:00
|
|
|
self.addEventListener('fetch', (e) => {
|
|
|
|
|
if (e.request.url.includes('/terminal')) return;
|
2026-04-24 07:44:01 +00:00
|
|
|
if (new URL(e.request.url).pathname.startsWith('/api/')) return;
|
2026-03-30 14:23:28 +00:00
|
|
|
e.respondWith(
|
|
|
|
|
caches.match(e.request).then((r) => r || fetch(e.request))
|
|
|
|
|
);
|
|
|
|
|
});
|