1// SW èªèº«å°±æå å¨äº§ç©æ ¹ç®å½ï¼æ å ¶ scope å³æè½½ç¹æ ¹ï¼ 2// æ é Service-Worker-Allowed 头å³å¯å¨ä»»ææè½½ç¹çæã 3const SCOPE = new URL(self.registration.scope).pathname 4const MANIFEST_PATH = `${SCOPE}pwa/manifest_v2` 5// æ§å®è£ çç¼åé®ä»æ¯åºå®è·¯å¾ï¼ä¿çåªè¯»åéé¿å å级ååä¸å° manifestã 6const LEGACY_MANIFEST_PATHS = ['/pwa/manifest_v2', '/normal/pwa/manifest_v2'] 7 8self.addEventListener('install', (event) => { 9 event.waitUntil(self.skipWaiting()) 10}) 11 12self.addEventListener('activate', (event) => { 13 event.waitUntil(self.clients.claim()) 14}) 15 16self.addEventListener('fetch', (event) => { 17 const requestUrl = new URL(event.request.url) 18 if (requestUrl.origin !== self.location.origin) return 19 if (requestUrl.pathname !== MANIFEST_PATH && !LEGACY_MANIFEST_PATHS.includes(requestUrl.pathname)) { 20 return 21 } 22 23 event.respondWith( 24 caches.open('manifest').then(async (cache) => { 25 // 带å 容æ è¯ç manifest å¿ é¡»ç²¾ç¡®å½ä¸ï¼ä¸è½åéå°å¦ä¸ä¸ªç«ç¹/æ¸ éçé ç½®ã 26 const cacheKey = requestUrl.searchParams.has('key') ? event.request : requestUrl.pathname 27 const cachedResponse = await cache.match(cacheKey) 28 29 if (cachedResponse) { 30 return cachedResponse 31 } 32 33 return new Response('{}', { 34 status: 200, 35 headers: { 36 'Content-Type': 'application/json', 37 'Cache-Control': 'no-store' 38 } 39 }) 40 }) 41 ) 42})
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.