PageSourceSearch

https://www.rashediqbal.me/sw.js

js rashediqbal.me collected 2026-09-26 04:58:01 UTC 5,169 bytes, 175 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-d44e78a9118b537cba18.js"
31  },
32  {
33    "url": "framework-551fae1afe52680d3eff.js"
34  },
35  {
36    "url": "app-ad213e92d500dd3ec526.js"
37  },
38  {
39    "url": "offline-plugin-app-shell-fallback/index.html",
40    "revision": "1ff5dba868352abbced4e3afd34607f7"
41  },
42  {
43    "url": "manifest.webmanifest",
44    "revision": "0fe977f0fc15d9dbcc76813666f34520"
45  }
46].concat(self.__precacheManifest || []);
47workbox.precaching.precacheAndRoute(self.__precacheManifest, {});
48
49workbox.routing.registerRoute(/(\.js$|\.css$|static\/)/, new workbox.strategies.CacheFirst(), 'GET');
50workbox.routing.registerRoute(/^https?:.*\/page-data\/.*\.json/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
51workbox.routing.registerRoute(/^https?:.*\.(png|jpg|jpeg|webp|avif|svg|gif|tiff|js|woff|woff2|json|css)$/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
52workbox.routing.registerRoute(/^https?:\/\/fonts\.googleapis\.com\/css/, new workbox.strategies.StaleWhileRevalidate(), 'GET');
53
54/* global importScripts, workbox, idbKeyval */
55importScripts(`idb-keyval-3.2.0-iife.min.js`)
56
57const { NavigationRoute } = workbox.routing
58
59let lastNavigationRequest = null
60let offlineShellEnabled = true
61
62// prefer standard object syntax to support more browsers
63const MessageAPI = {
64  setPathResources: (event, { path, resources }) => {
65    event.waitUntil(idbKeyval.set(`resources:${path}`, resources))
66  },
67
68  clearPathResources: event => {
69    event.waitUntil(idbKeyval.clear())
70
71    // We detected compilation hash mismatch
72    // we should clear runtime cache as data
73    // files might be out of sync and we should
74    // do fresh fetches for them
75    event.waitUntil(
76      caches.keys().then(function (keyList) {
77        return Promise.all(
78          keyList.map(function (key) {
79            if (key && key.includes(`runtime`)) {
80              return caches.delete(key)
81            }
82
83            return Promise.resolve()
84          })
85        )
86      })
87    )
88  },
89
90  enableOfflineShell: () => {
91    offlineShellEnabled = true
92  },
93
94  disableOfflineShell: () => {
95    offlineShellEnabled = false
96  },
97}
98
99self.addEventListener(`message`, event => {
100  const { gatsbyApi: api } = event.data
101  if (api) MessageAPI[api](event, event.data)
102})
103
104function handleAPIRequest({ event }) {
105  const { pathname } = new URL(event.request.url)
106
107  const params = pathname.match(/:(.+)/)[1]
108  const data = {}
109
110  if (params.includes(`=`)) {
111    params.split(`&`).forEach(param => {
112      const [key, val] = param.split(`=`)
113      data[key] = val
114    })
115  } else {
116    data.api = params
117  }
118
119  if (MessageAPI[data.api] !== undefined) {
120    MessageAPI[data.api]()
121  }
122
123  if (!data.redirect) {
124    return new Response()
125  }
126
127  return new Response(null, {
128    status: 302,
129    headers: {
130      Location: lastNavigationRequest,
131    },
132  })
133}
134
135const navigationRoute = new NavigationRoute(async ({ event }) => {
136  // handle API requests separately to normal navigation requests, so do this
137  // check first
138  if (event.request.url.match(/\/.gatsby-plugin-offline:.+/)) {
139    return handleAPIRequest({ event })
140  }
141
142  if (!offlineShellEnabled) {
143    return await fetch(event.request)
144  }
145
146  lastNavigationRequest = event.request.url
147
148  let { pathname } = new URL(event.request.url)
149  pathname = pathname.replace(new RegExp(`^`), ``)
150
151  // Check for resources + the app bundle
152  // The latter may not exist if the SW is updating to a new version
153  const resources = await idbKeyval.get(`resources:${pathname}`)
154  if (!resources || !(await caches.match(`/app-ad213e92d500dd3ec526.js`))) {
155    return await fetch(event.request)
156  }
157
158  for (const resource of resources) {
159    // As soon as we detect a failed resource, fetch the entire page from
160    // network - that way we won't risk being in an inconsistent state with
161    // some parts of the page failing.
162    if (!(await caches.match(resource))) {
163      return await fetch(event.request)
164    }
165  }
166
167  const offlineShell = `/offline-plugin-app-shell-fallback/index.html`
168  const offlineShellWithKey = workbox.precaching.getCacheKeyForURL(offlineShell)
169  return await caches.match(offlineShellWithKey)
170})
171
172workbox.routing.registerRoute(navigationRoute)
173
174// this route is used when performing a non-navigation request (e.g. fetch)
175workbox.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.