PageSourceSearch

https://ipconfig.io/sw.js

js ipconfig.io collected 2026-10-07 03:04:26 UTC 1,944 bytes, 56 lines download raw bytes

1// ipconfig.io service worker: offline app shell + installability.
2//
3// The page is per-IP and dynamic, so navigations are network-first (always
4// fetch the real IP) with the last response as an offline fallback. The static
5// shell (icons, manifest) is cache-first. API endpoints pass straight through.
6var VERSION = 'v1';
7var CACHE = 'ipconfig-' + VERSION;
8var ASSETS = ['/icon-192.png', '/icon-512.png', '/apple-touch-icon.png', '/manifest.webmanifest'];
9
10self.addEventListener('install', function (e) {
11  e.waitUntil(
12    caches.open(CACHE).then(function (c) { return c.addAll(ASSETS); }).then(function () {
13      return self.skipWaiting();
14    })
15  );
16});
17
18self.addEventListener('activate', function (e) {
19  e.waitUntil(
20    caches.keys().then(function (keys) {
21      return Promise.all(keys.filter(function (k) { return k !== CACHE; }).map(function (k) {
22        return caches.delete(k);
23      }));
24    }).then(function () { return self.clients.claim(); })
25  );
26});
27
28self.addEventListener('fetch', function (e) {
29  var req = e.request;
30  if (req.method !== 'GET') { return; }
31  var url = new URL(req.url);
32  if (url.origin !== self.location.origin) { return; }
33
34  // The dashboard itself: network-first, fall back to the last cached page when
35  // offline (or an icon if there isn't one yet).
36  if (req.mode === 'navigate') {
37    e.respondWith(
38      fetch(req).then(function (res) {
39        var copy = res.clone();
40        caches.open(CACHE).then(function (c) { c.put('/', copy); });
41        return res;
42      }).catch(function () {
43        return caches.match('/').then(function (r) { return r || caches.match('/icon-192.png'); });
44      })
45    );
46    return;
47  }
48
49  // Static shell assets: cache-first.
50  if (ASSETS.indexOf(url.pathname) !== -1) {
51    e.respondWith(caches.match(req).then(function (r) { return r || fetch(req); }));
52    return;
53  }
54
55  // Everything else (API endpoints, etc.): straight to the network, uncached.
56});

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.