1const CACHE_NAME = 'softera-ai-v3.0.0'; 2const STATIC_CACHE = 'softera-static-v3.0.0'; 3const DYNAMIC_CACHE = 'softera-dynamic-v3.0.0'; 4const IMAGE_CACHE = 'softera-images-v3.0.0'; 5 6const urlsToCache = [ 7 '/', 8 '/manifest.json', 9 '/favicon.ico', 10 '/solutions', 11 '/services', 12 '/industries', 13 '/why-softera', 14 '/contact', 15 '/faq' 16]; 17 18// Install event - cache resources 19self.addEventListener('install', (event) => { 20 event.waitUntil( 21 caches.open(STATIC_CACHE) 22 .then((cache) => { 23 console.log('Caching app shell and static resources'); 24 return Promise.all( 25 urlsToCache.map(url => 26 cache.add(url).catch(err => console.log('Failed to cache:', url, err)) 27 ) 28 ); 29 }) 30 .then(() => self.skipWaiting()) 31 .catch(err => console.log('SW install error:', err)) 32 ); 33}); 34 35// Activate event - clean up old caches and take control 36self.addEventListener('activate', (event) => { 37 event.waitUntil( 38 Promise.all([ 39 caches.keys().then((cacheNames) => { 40 return Promise.all( 41 cacheNames.map((cacheName) => { 42 if (cacheName !== STATIC_CACHE && cacheName !== DYNAMIC_CACHE) { 43 console.log('Deleting old cache:', cacheName); 44 return caches.delete(cacheName); 45 } 46 }) 47 ); 48 }), 49 self.clients.claim() 50 ]) 51 ); 52}); 53 54// Fetch event - implement network-first strategy for API calls, cache-first for static assets 55self.addEventListener('fetch', (event) => { 56 const { request } = event; 57 58 // Skip non-GET requests 59 if (request.method !== 'GET') { 60 return; 61 } 62 63 // Handle API requests with network-first strategy 64 if (request.url.includes('/api/')) { 65 event.respondWith( 66 fetch(request) 67 .then((response) => { 68 const responseClone = response.clone(); 69 caches.open(DYNAMIC_CACHE) 70 .then((cache) => cache.put(request, responseClone)); 71 return response; 72 }) 73 .catch(() => caches.match(request)) 74 ); 75 return; 76 } 77 78 // Handle static assets with cache-first strategy 79 event.respondWith( 80 caches.match(request) 81 .then((response) => { 82 if (response) { 83 return response; 84 } 85 86 return fetch(request) 87 .then((response) => { 88 // Don't cache non-successful responses 89 if (!response || response.status !== 200 || response.type !== 'basic') { 90 return response; 91 } 92 93 const responseToCache = response.clone(); 94 caches.open(DYNAMIC_CACHE) 95 .then((cache) => { 96 cache.put(request, responseToCache); 97 }); 98 99 return response; 100 }); 101 }) 102 .catch(() => { 103 // Return offline fallback for navigation requests 104 if (request.destination === 'document') { 105 return caches.match('/'); 106 } 107 }) 108 ); 109});
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.