Spaces:
Runtime error
Runtime error
File size: 1,166 Bytes
0666741 1829c17 0666741 1829c17 0666741 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 | // STEM Copilot — Service Worker (PWA installability + basic cache)
const CACHE_NAME = 'stemcopilot-v2';
const SHELL_URLS = [
'/',
'/static/style.css',
'/static/app.js',
'/assets/bot.png',
'/assets/stem_black.png',
'/assets/stembotix.png',
];
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(CACHE_NAME).then((cache) => cache.addAll(SHELL_URLS))
);
self.skipWaiting();
});
self.addEventListener('activate', (e) => {
e.waitUntil(
caches.keys().then((keys) =>
Promise.all(keys.filter((k) => k !== CACHE_NAME).map((k) => caches.delete(k)))
)
);
self.clients.claim();
});
self.addEventListener('fetch', (e) => {
// Network-first for API calls, cache-first for shell assets
if (e.request.url.includes('/chat') || e.request.url.includes('/auth') ||
e.request.url.includes('/threads') || e.request.url.includes('/history') ||
e.request.url.includes('/user') || e.request.url.includes('/export') ||
e.request.url.includes('/health')) {
return; // Let these go straight to network
}
e.respondWith(
caches.match(e.request).then((cached) => cached || fetch(e.request))
);
});
|