PageSourceSearch

https://blog.xapi.ly/sw.js

js xapi.ly collected 2026-10-05 02:50:05 UTC 5,411 bytes, 187 lines download raw bytes

1/**
2 * Welcome to your Workbox-powered service worker!
3 *
4 * You'll need to register this file in your web app and you should
5 * disable HTTP caching for this file too.
6 * See https://goo.gl/nhQhGp
7 *
8 * The rest of the code is auto-generated. Please don't update this file
9 * directly; instead, make changes to your Workbox build configuration
10 * and re-run your build process.
11 * See https://goo.gl/2aRDsh
12 */
13
14importScripts("workbox-v4.3.1/workbox-sw.js");
15workbox.setConfig({modulePathPrefix: "workbox-v4.3.1"});
16
17workbox.core.setCacheNameDetails({prefix: "gatsby-plugin-offline"});
18
19workbox.core.skipWaiting();
20
21workbox.core.clientsClaim();
22
23/**
24 * The workboxSW.precacheAndRoute() method efficiently caches and responds to
25 * requests for URLs in the manifest.
26 * See https://goo.gl/S9QRab
27 */
28self.__precacheManifest = [
29  {
30    "url": "webpack-runtime-00ac0b057aade1ed903a.js"
31  },
32  {
33    "url": "styles.efbeeb0c6650ddcb75ea.css"
34  },
35  {
36    "url": "styles-407fe62976dc5310c43e.js"
37  },
38  {
39    "url": "framework-0c07c9218e9798907e47.js"
40  },
41  {
42    "url": "532a2f07-c4c0ebf5d8fccdd5655d.js"
43  },
44  {
45    "url": "dc6a8720040df98778fe970bf6c000a41750d3ae-1ebc5f4b22b0db598f93.js"
46  },
47  {
48    "url": "app-2573ac4890da19b4d62f.js"
49  },
50  {
51    "url": "offline-plugin-app-shell-fallback/index.html",
52    "revision": "b815f3d5c8416ee42c778328bd6fa525"
53  },
54  {
55    "url": "component---cache-caches-gatsby-plugin-offline-app-shell-js-a95b272f8c25b9a8a758.js"
56  },
57  {
58    "url": "page-data/offline-plugin-app-shell-fallback/page-data.json",
59    "revision": "f6081b83111aea4128c98944b7fafccc"
60  },
61  {
62    "url": "page-data/app-data.json",
63    "revision": "48deb12a4186f7f865e32a7d626121a0"
64  },
65  {
66    "url": "polyfill-97c5926e64c58e1a9b70.js"
67  },
68  {
69    "url": "manifest.json",
70    "revision": "525f8fdc673f544887998e2e653a54c5"
71  },
72  {
73    "url": "manifest.webmanifest",
74    "revision": "713fb10d6d1a9997d2bca14ba995152f"
75  }
76].concat(self.__precacheManifest || []);
77workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
78
79workbox.routing.registerRoute(/(\.js$|\.css$|[^:]static\/)/, new workbox.strategies.CacheFirst(), 'GET');
80workbox.routing.registerRoute(/^https?:.*\/page-data\/.*\.json/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
81workbox.routing.registerRoute(/^https?:.*\.(png|jpg|jpeg|webp|svg|gif|tiff|js|woff|woff2|json|css)$/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
82workbox.routing.registerRoute(/^https?:\/\/fonts\.googleapis\.com\/css/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
83
84/* global importScripts, workbox, idbKeyval */
85importScripts(`idb-keyval-3.2.0-iife.min.js`)
86
87const { NavigationRoute } = workbox.routing
88
89let lastNavigationRequest = null
90let offlineShellEnabled = true
91
92// prefer standard object syntax to support more browsers
93const MessageAPI = {
94  setPathResources: (event, { path, resources }) => {
95    event.waitUntil(idbKeyval.set(`resources:${path}`, resources))
96  },
97
98  clearPathResources: event => {
99    event.waitUntil(idbKeyval.clear())
100  },
101
102  enableOfflineShell: () => {
103    offlineShellEnabled = true
104  },
105
106  disableOfflineShell: () => {
107    offlineShellEnabled = false
108  },
109}
110
111self.addEventListener(`message`, event => {
112  const { gatsbyApi: api } = event.data
113  if (api) MessageAPI[api](event, event.data)
114})
115
116function handleAPIRequest({ event }) {
117  const { pathname } = new URL(event.request.url)
118
119  const params = pathname.match(/:(.+)/)[1]
120  const data = {}
121
122  if (params.includes(`=`)) {
123    params.split(`&`).forEach(param => {
124      const [key, val] = param.split(`=`)
125      data[key] = val
126    })
127  } else {
128    data.api = params
129  }
130
131  if (MessageAPI[data.api] !== undefined) {
132    MessageAPI[data.api]()
133  }
134
135  if (!data.redirect) {
136    return new Response()
137  }
138
139  return new Response(null, {
140    status: 302,
141    headers: {
142      Location: lastNavigationRequest,
143    },
144  })
145}
146
147const navigationRoute = new NavigationRoute(async ({ event }) => {
148  // handle API requests separately to normal navigation requests, so do this
149  // check first
150  if (event.request.url.match(/\/.gatsby-plugin-offline:.+/)) {
151    return handleAPIRequest({ event })
152  }
153
154  if (!offlineShellEnabled) {
155    return await fetch(event.request)
156  }
157
158  lastNavigationRequest = event.request.url
159
160  let { pathname } = new URL(event.request.url)
161  pathname = pathname.replace(new RegExp(`^`), ``)
162
163  // Check for resources + the app bundle
164  // The latter may not exist if the SW is updating to a new version
165  const resources = await idbKeyval.get(`resources:${pathname}`)
166  if (!resources || !(await caches.match(`/app-2573ac4890da19b4d62f.js`))) {
167    return await fetch(event.request)
168  }
169
170  for (const resource of resources) {
171    // As soon as we detect a failed resource, fetch the entire page from
172    // network - that way we won't risk being in an inconsistent state with
173    // some parts of the page failing.
174    if (!(await caches.match(resource))) {
175      return await fetch(event.request)
176    }
177  }
178
179  const offlineShell = `/offline-plugin-app-shell-fallback/index.html`
180  const offlineShellWithKey = workbox.precaching.getCacheKeyForURL(offlineShell)
181  return await caches.match(offlineShellWithKey)
182})
183
184workbox.routing.registerRoute(navigationRoute)
185
186// this route is used when performing a non-navigation request (e.g. fetch)
187workbox.routing.registerRoute(/\/.gatsby-plugin-offline:.+/, handleAPIRequest)

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.