PageSourceSearch

https://www.halt.org/sw.js

js halt.org collected 2026-10-02 07:53:03 UTC 2,035 bytes, 80 lines download raw bytes

1// service-worker.js
2
3const CACHE_NAME = "all-cache-v1";
4
5// Install event - caches all assets
6self.addEventListener("install", (event) => {
7  event.waitUntil(
8    caches.open(CACHE_NAME).then((cache) => {
9      return cache.addAll([
10        // List all your assets here, including HTML, CSS, JavaScript, and image files
11        "/",
12        "/index.html",
13        "/styles.css",
14        "/script.js",
15        "/images/logo.png",
16        // You can also add more files here
17      ]);
18    })
19  );
20});
21
22// Activate event - cleans up old caches
23self.addEventListener("activate", (event) => {
24  const cacheWhitelist = [CACHE_NAME];
25  event.waitUntil(
26    caches.keys().then((cacheNames) => {
27      return Promise.all(
28        cacheNames.map((cacheName) => {
29          if (cacheWhitelist.indexOf(cacheName) === -1) {
30            return caches.delete(cacheName);
31          }
32        })
33      );
34    })
35  );
36});
37
38// Fetch event - caches new requests cumulatively
39self.addEventListener("fetch", (event) => {
40  event.respondWith(
41    caches.match(event.request).then((response) => {
42      // Return cached response if found
43      if (response) {
44        return response;
45      }
46
47      return fetch(event.request).then((response) => {
48        // Don't cache if not a successful response
49        if (!response || response.status !== 200 || response.type !== "basic") {
50          return response;
51        }
52
53        const responseToCache = response.clone();
54
55        caches.open(CACHE_NAME).then((cache) => {
56          cache.put(event.request, responseToCache);
57        });
58
59        return response;
60      });
61    })
62  );
63});
64// main.js
65
66if ("serviceWorker" in navigator) {
67  window.addEventListener("load", () => {
68    navigator.serviceWorker.register("/service-worker.js").then(
69      (registration) => {
70        console.log(
71          "ServiceWorker registration successful with scope: ",
72          registration.scope
73        );
74      },
75      (err) => {
76        console.log("ServiceWorker registration failed: ", err);
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.