PageSourceSearch

https://bd777.dev/sw.js

js bd777.dev collected 2026-10-04 05:46:08 UTC 2,057 bytes, 65 lines download raw bytes

1/* Cache static assets and provide an offline fallback. */
2const CACHE_VERSION = 'bd777-v1';
3const OFFLINE_URL = '/offline/';
4const OFFLINE_URL_EN = '/en/offline/';
5
6const PRECACHE_URLS = [
7  '/',
8  OFFLINE_URL,
9  OFFLINE_URL_EN,
10  '/manifest.json',
11  '/icons/icon.svg',
12];
13
14self.addEventListener('install', (event) => {
15  event.waitUntil(
16    caches.open(CACHE_VERSION).then((cache) => cache.addAll(PRECACHE_URLS)).then(() => self.skipWaiting())
17  );
18});
19
20self.addEventListener('activate', (event) => {
21  event.waitUntil(
22    caches.keys().then((keys) =>
23      Promise.all(keys.filter((key) => key !== CACHE_VERSION).map((key) => caches.delete(key)))
24    ).then(() => self.clients.claim())
25  );
26});
27
28self.addEventListener('fetch', (event) => {
29  const { request } = event;
30  if (request.method !== 'GET') return;
31
32  const url = new URL(request.url);
33  if (url.origin !== self.location.origin) return;
34
35  // Prefer the network and fall back to the offline page.
36  if (request.mode === 'navigate') {
37    const offlineUrl = url.pathname.startsWith('/en/') ? OFFLINE_URL_EN : OFFLINE_URL;
38    event.respondWith(
39      fetch(request)
40        .then((response) => {
41          const copy = response.clone();
42          caches.open(CACHE_VERSION).then((cache) => cache.put(request, copy));
43          return response;
44        })
45        .catch(() => caches.match(request).then((cached) => cached || caches.match(offlineUrl)))
46    );
47    return;
48  }
49
50  // Prefer cached static assets and refresh them from the network.
51  event.respondWith(
52    caches.match(request).then((cached) => {
53      if (cached) return cached;
54      return fetch(request)
55        .then((response) => {
56          if (response.ok && (request.destination === 'style' || request.destination === 'script' || request.destination === 'image' || request.destination === 'font')) {
57            const copy = response.clone();
58            caches.open(CACHE_VERSION).then((cache) => cache.put(request, copy));
59          }
60          return response;
61        })
62        .catch(() => cached);
63    })
64  );
65});

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.