PageSourceSearch

https://appiplwin.com/normal/sw.js

js appiplwin.com collected 2026-10-09 23:37:28 UTC 1,467 bytes, 42 lines download raw bytes

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.