1const CACHE_NAME = 'sundream-cache-v6'; 2const STATIC_ASSETS = [ 3 '/manifest.json', 4 '/favicon.png' 5]; 6 7// Install Event - ì¦ì ì ë²ì íì±í ì¤ë¹ 8self.addEventListener('install', (event) => { 9 self.skipWaiting(); 10 event.waitUntil( 11 caches.open(CACHE_NAME).then((cache) => { 12 return cache.addAll(STATIC_ASSETS); 13 }) 14 ); 15}); 16 17// Activate Event - Clean up old caches 18self.addEventListener('activate', (event) => { 19 event.waitUntil( 20 caches.keys().then((cacheNames) => { 21 return Promise.all( 22 cacheNames.map((cacheName) => { 23 if (cacheName !== CACHE_NAME) { 24 return caches.delete(cacheName); 25 } 26 }) 27 ); 28 }).then(() => self.clients.claim()) 29 ); 30}); 31 32// Fetch Event - Network First for HTML, Cache First for Others 33self.addEventListener('fetch', (event) => { 34 const { request } = event; 35 const url = new URL(request.url); 36 37 // Bypass cache completely on local development hosts 38 const host = self.location.hostname; 39 const isLocal = host === 'localhost' || 40 host === '127.0.0.1' || 41 host.startsWith('192.168.') || 42 host.startsWith('10.') || 43 host.endsWith('.local'); 44 if (isLocal) { 45 event.respondWith(fetch(request)); 46 return; 47 } 48 49 // For HTML pages, use Network First 50 if (request.mode === 'navigate' || (request.method === 'GET' && request.headers.get('accept').includes('text/html'))) { 51 event.respondWith( 52 fetch(request) 53 .then((response) => { 54 const copy = response.clone(); 55 caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)); 56 return response; 57 }) 58 .catch(() => caches.match(request)) 59 ); 60 return; 61 } 62 63 // For Static Assets (scripts, styles, images) on the SAME ORIGIN, use Cache First 64 if (url.origin === self.location.origin) { 65 event.respondWith( 66 caches.match(request).then((response) => { 67 return response || fetch(request).then((networkResponse) => { 68 if (networkResponse && networkResponse.status === 200) { 69 const copy = networkResponse.clone(); 70 caches.open(CACHE_NAME).then((cache) => cache.put(request, copy)); 71 } 72 return networkResponse; 73 }); 74 }) 75 ); 76 } else { 77 // For External APIs (Supabase etc), ALWAYS use Network (No Cache) 78 event.respondWith(fetch(request)); 79 } 80});
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.