PageSourceSearch

https://violetpictures.co.uk/sw.js

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