1const CACHE_NAME = "r2eai-public-shell-v1"; 2const OFFLINE_PAGE = "/r2e-offline.html"; 3const STATIC_ASSET_PATH = /^\/assets\/.+\.(?:css|js|mjs|woff2?|ttf|svg|png|webp|jpe?g|gif|ico)$/i; 4 5function isCacheablePublicAsset(url) { 6 return url.origin === self.location.origin && STATIC_ASSET_PATH.test(url.pathname); 7} 8 9self.addEventListener("install", (event) => { 10 event.waitUntil(caches.open(CACHE_NAME).then((cache) => cache.addAll(["/", OFFLINE_PAGE]))); 11 self.skipWaiting(); 12}); 13 14self.addEventListener("activate", (event) => { 15 event.waitUntil( 16 caches.keys().then((keys) => 17 Promise.all(keys.filter((key) => key.startsWith("r2eai-public-shell-") && key !== CACHE_NAME).map((key) => caches.delete(key))) 18 ) 19 ); 20 self.clients.claim(); 21}); 22 23self.addEventListener("fetch", (event) => { 24 const request = event.request; 25 if (request.method !== "GET") return; 26 const url = new URL(request.url); 27 28 // ä¸å¿«å tRPC/APIãæå¡é è³æãåå交æãS3 ä¸å³å §å®¹æä»»ä½å¤é¨è³æºã 29 if (url.origin !== self.location.origin || url.pathname.startsWith("/api/") || url.pathname.startsWith("/manus-storage/")) return; 30 31 if (request.mode === "navigate") { 32 event.respondWith( 33 fetch(request) 34 .then((response) => { 35 if (response.ok) { 36 void caches.open(CACHE_NAME).then((cache) => cache.put("/", response.clone())); 37 } 38 return response; 39 }) 40 .catch(() => caches.match(OFFLINE_PAGE)) 41 ); 42 return; 43 } 44 45 if (!isCacheablePublicAsset(url)) return; 46 event.respondWith( 47 caches.match(request).then((cached) => { 48 const networkResponse = fetch(request) 49 .then((response) => { 50 if (response.ok) void caches.open(CACHE_NAME).then((cache) => cache.put(request, response.clone())); 51 return response; 52 }) 53 .catch(() => cached ?? Response.error()); 54 return cached || networkResponse; 55 }) 56 ); 57});
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.