1const manifestBuildVer = '1.0.17'; 2 3const CACHE_NAME = 'site-cache-v20.04'; // Bumped version to force mobile system flush 4const ASSETS_TO_CACHE = [ 5 //'/', 6 //'/?source=pwa', 7 '/offline', 8 '/favicon.ico', 9 `/manifest.json?v=${manifestBuildVer}`, 10 11 // 1. Core UI Pages (Static) 12 // '/about', 13 // '/contact', 14 15 // 2. Critical UI Stylesheets & Scripts 16 // `/min/production.min.css?v=${cssBuildVer}`, 17 // `/min/production.min.js?v=${jsBuildVer}`, 18 // '/js/custom/js/components/dark-mode/v4/toggleDarkModeFirstLoad-v4.min.js', 19 20 // 3. Branding & Icon Essentials 21 '/images/common/thumbnail_logo.png', 22 '/images/common/app/logo/icon-192.png', 23 '/images/common/app/logo/icon-512.png' 24]; 25 26// 1. Install Event: Save essential files to the browser's cache 27self.addEventListener('install', (event) => { 28 self.skipWaiting(); // Forces the new service worker to become active immediately 29 event.waitUntil( 30 caches.open(CACHE_NAME).then((cache) => cache.addAll(ASSETS_TO_CACHE)) 31 ); 32}); 33 34// 2. Fetch Event: Serve files from cache if the user is offline 35// self.addEventListener('fetch', (event) => { 36// event.respondWith( 37// caches.match(event.request).then((response) => { 38// return response || fetch(event.request); 39// }) 40// ); 41// }); 42 43// self.addEventListener('fetch', (event) => { 44// // Only handle GET requests (don't cache POST/PUT/DELETE) 45// if (event.request.method !== 'GET') return; 46 47// event.respondWith( 48// caches.match(event.request).then((cachedResponse) => { 49// if (cachedResponse) { 50// return cachedResponse; 51// } 52 53// // // 2. NEW: Bypass Service Worker for Adblock detection 54// // // This prevents the SW from "remembering" a failed/blocked state 55// // if (event.request.url.includes('googlesyndication.com')) { 56// // return; // Let the browser handle this normally via network 57// // } 58 59// return fetch(event.request).catch(() => { 60// // If both cache and network fail, and it's a page request: 61// if (event.request.mode === 'navigate') { 62// //return caches.match('/'); // Or a dedicated /offline page 63// return caches.match('/offline'); // Branded fallback 64// } 65// }); 66// }) 67// ); 68// }); 69 70self.addEventListener('fetch', (event) => { 71 // 1. Only handle GET requests 72 if (event.request.method !== 'GET') return; 73 74 const url = event.request.url; 75 76 // BYPASS: Ignore WebSockets and Socket.io traffic 77 // check at the very top of your fetch listener 78 // IGNORE WEBSOCKETS IMMEDIATELY 79 // Ensure socket.io bypass is at the TOP of your fetch logic 80 if (url.startsWith('wss:') || url.startsWith('ws:') || url.includes('/socket.io/')) { 81 return; // Do nothing, let the browser handle it natively 82 } 83 84 // BYPASS: Ignore Ad-scripts 85 // 2. NEW: Bypass Service Worker for Adblock detection 86 // This prevents the SW from "remembering" a failed/blocked state 87 if (event.request.url.includes('googlesyndication.com')) { 88 return; // Let the browser handle this normally via network 89 } 90 91 event.respondWith( 92 caches.match(event.request).then((cachedResponse) => { 93 if (cachedResponse) { 94 return cachedResponse; 95 } 96 97 return fetch(event.request).catch(() => { 98 if (event.request.mode === 'navigate') { 99 return caches.match('/offline'); 100 } 101 }); 102 }) 103 ); 104}); 105 106 107// 3. Activate Event: Clean up old versions of the cache 108self.addEventListener('activate', (event) => { 109 console.log('[sw-caching.js] Service Worker: Activated'); 110 event.waitUntil( 111 caches.keys().then((cacheNames) => { 112 return Promise.all( 113 cacheNames.map((cache) => { 114 if (cache !== CACHE_NAME) { 115 console.log('Service Worker: Clearing Old Cache'); 116 return caches.delete(cache); 117 } 118 }) 119 ); 120 }) 121 ); 122});
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.