1const CACHE_NAME = '3d-flags-cache-v3'; 2const MEDIA_CACHE = '3d-media-cache-v1'; 3 4// ÐÑÑÐ°Ð½Ð¾Ð²Ð»ÐµÐ½Ð½Ñ 5self.addEventListener('install', (event) => { 6 event.waitUntil( 7 Promise.all([ 8 caches.open(CACHE_NAME), 9 caches.open(MEDIA_CACHE) 10 ]) 11 ); 12 self.skipWaiting(); 13}); 14 15// ÐкÑиваÑÑÑ 16self.addEventListener('activate', (event) => { 17 event.waitUntil( 18 caches.keys().then(cacheNames => { 19 return Promise.all( 20 cacheNames.map(cacheName => { 21 // ÐидалÑÑмо ÑÑаÑÑ Ð²ÐµÑÑÑÑ ÐºÐµÑÑв 22 if (cacheName !== CACHE_NAME && cacheName !== MEDIA_CACHE) { 23 return caches.delete(cacheName); 24 } 25 }) 26 ); 27 }) 28 ); 29 self.clients.claim(); 30}); 31 32// СÑÑаÑегÑÑ ÐºÐµÑÑÐ²Ð°Ð½Ð½Ñ 33self.addEventListener('fetch', (event) => { 34 const { request } = event; 35 const url = new URL(request.url); 36 37 // ÐгноÑÑÑмо не-HTTP запиÑи (chrome-extension, chrome://, ÑоÑо) 38 if (!url.protocol.startsWith('http')) { 39 return; 40 } 41 42 // ÐÑопÑÑкаÑмо API запиÑи 43 if (url.pathname.includes('/api/')) { 44 return; 45 } 46 47 // ÐÑопÑÑкаÑмо навÑгаÑÑÑ 48 if (request.mode === 'navigate') { 49 return; 50 } 51 52 // ÐеÑÑÑмо ÐСРмедÑа Ñайли 53 const isMedia = 54 url.pathname.match(/\.(fbx|glb|gltf|png|jpg|jpeg|webp|hdr|svg)$/i) || 55 url.pathname.includes('/models/') || 56 url.pathname.includes('/textures/') || 57 url.pathname.includes('/environments/') || 58 url.pathname.includes('/uploads/'); 59 60 if (isMedia) { 61 event.respondWith( 62 caches.open(MEDIA_CACHE).then(cache => { 63 return cache.match(request).then(response => { 64 // ЯкÑо Ñ Ð² кеÑÑ - повеÑÑаÑмо 65 if (response) { 66 return response; 67 } 68 // ЯкÑо Ð½ÐµÐ¼Ð°Ñ - заванÑажÑÑмо Ñ ÐºÐµÑÑÑмо 69 return fetch(request).then(response => { 70 // ÐеÑÑÑмо ÑÑлÑки ÑÑпÑÑÐ½Ñ Ð²ÑдповÑÐ´Ñ 71 if (response && response.ok && response.status === 200) { 72 cache.put(request, response.clone()); 73 } 74 return response; 75 }); 76 }); 77 }) 78 ); 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.