1const CACHE_NAME = 'mystery-podcast-v7'; 2const urlsToCache = [ 3 '/', 4 '/manifest.json' 5]; 6 7// Install event - claim clients immediately 8self.addEventListener('install', (event) => { 9 event.waitUntil( 10 caches.open(CACHE_NAME) 11 .then((cache) => { 12 return cache.addAll(urlsToCache); 13 }) 14 .then(() => { 15 return self.skipWaiting(); 16 }) 17 ); 18}); 19 20// Activate event - take control immediately 21self.addEventListener('activate', (event) => { 22 event.waitUntil( 23 caches.keys().then((cacheNames) => { 24 return Promise.all([ 25 ...cacheNames.map((cacheName) => { 26 if (cacheName !== CACHE_NAME) { 27 return caches.delete(cacheName); 28 } 29 }), 30 self.clients.claim() 31 ]); 32 }) 33 ); 34}); 35 36// Fetch event - network first, then cache 37self.addEventListener('fetch', (event) => { 38 // Only handle GET requests 39 if (event.request.method !== 'GET') { 40 return; 41 } 42 43 // Let the browser handle audio and byte-range requests directly. Media 44 // playback relies on partial responses, which should not be cached or 45 // proxied through this offline cache strategy. 46 const requestUrl = new URL(event.request.url); 47 const isAudioRequest = /\.(mp3|m4a|aac|wav|ogg)$/i.test(requestUrl.pathname); 48 const isAdminRequest = requestUrl.pathname.startsWith('/admin'); 49 const isPageNavigation = event.request.mode === 'navigate'; 50 if (isAudioRequest || isAdminRequest || isPageNavigation || event.request.headers.has('range')) { 51 return; 52 } 53 54 event.respondWith( 55 fetch(event.request) 56 .then((response) => { 57 // Only cache successful GET requests for non-API routes 58 if (response.status === 200 && event.request.method === 'GET' && !event.request.url.includes('/api/')) { 59 const responseClone = response.clone(); 60 caches.open(CACHE_NAME) 61 .then((cache) => { 62 cache.put(event.request, responseClone); 63 }) 64 .catch((err) => { 65 // Silently fail cache errors 66 console.log('Cache put failed:', err); 67 }); 68 } 69 return response; 70 }) 71 .catch(() => { 72 // If network fails, try cache 73 return caches.match(event.request); 74 }) 75 ); 76});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.