PageSourceSearch

https://www.musichouseschool.com/serviceworker.js

js musichouseschool.com collected 2026-10-05 07:25:13 UTC 3,782 bytes, 103 lines download raw bytes

1var CACHE_FIRST_CACHE_NAME = '1:sw-cache-'
2var CDN_CACHE_NAME = 'CDN'
3
4function onInstall(event) {
5  event.waitUntil(
6    caches.open(CACHE_FIRST_CACHE_NAME).then(cache => {
7      return cache.addAll(["https://fonts.gstatic.com/s/poppins/v1/D2gN9uyZ9Ucx1fJ1Fhb7swzyDMXhdD8sAj6OAJTFsBI.woff2","https://fonts.gstatic.com/s/poppins/v1/yQWaOD4iNU5NTY0apN-qjwzyDMXhdD8sAj6OAJTFsBI.woff2","https://fonts.gstatic.com/s/poppins/v1/57TQ-anwthzkETEIO4jESAzyDMXhdD8sAj6OAJTFsBI.woff2","/fonts/Phosphate-Solid.woff2","/offline","https://cdn.musichouseschool.com/logos/padded-logo-oct-2020.svg","https://cdn.musichouseschool.com/logos/apple-touch-icon.png"])
8    })
9  )
10}
11
12function onActivate(event) {
13  event.waitUntil(
14    caches.keys().then(cacheNames => {
15      return Promise.all(
16        cacheNames.filter(cacheName => {
17          // Return true if you want to remove this cache, but remember that caches are shared across the whole origin.
18          return cacheName !== CACHE_FIRST_CACHE_NAME && cacheName !== CDN_CACHE_NAME
19        }).map(cacheName => {
20          return caches.delete(cacheName)
21        })
22      )
23    })
24  )
25}
26
27function onFetch(event) {
28  const cacheName = longLivedAssetRequest(event.request.url) ? CDN_CACHE_NAME : CACHE_FIRST_CACHE_NAME
29  event.respondWith(cacheFirstResponse(event.request, cacheName))
30}
31
32function cacheFirstResponse(request, cacheName) {
33  return caches.open(cacheName).then(cache => {
34    return cache.match(request).then(response => {
35      return response || networkFirstResponse(request, cacheName)
36    })
37  })
38}
39
40function longLivedAssetRequest(url) {
41  url.match(/^https:\/\/cdn.musichouseschool.com\//) || url.match(/^https:\/\/www.musichouseschool.com\/assets\//)
42}
43
44function networkFirstResponse(request, cacheName) {
45  if (cacheName === CDN_CACHE_NAME) {
46    // cache response for CDN assets
47    return caches.open(cacheName).then(cache => {
48      return fetch(request, { mode: "cors" }).then(response => {
49        cache.put(request, response.clone())
50        return response
51      }).catch(() => { return offlineResponse(request) })
52    })
53  } else {
54    // Do not cache
55    return fetch(request).then(response => {
56      return response
57    }).catch(() => { return offlineResponse(request) })
58  }
59}
60
61function offlineResponse(request) {
62  if (!offlineNavigation(request)) return
63  return caches.open(NETWORK_FIRST_CACHE_NAME).then(cache =>{
64    return cache.match(request).then(response => {
65      return response || caches.match('/offline')
66    })
67  })
68}
69
70function offlineNavigation(request) {
71  return request.mode === 'navigate' || (request.method === 'GET' && request.headers.get('accept').includes('text/html'))
72}
73
74self.addEventListener('install', onInstall)
75self.addEventListener('activate', onActivate)
76self.addEventListener('fetch', onFetch)
77
78self.addEventListener('push', (event) => {
79  const message = event.data.json()
80  const { title, ...options } = message.notification
81  // The "navigate" key is not passed from the push message to the Notification, so pass it via data.
82  options.data = { "url": options.navigate }
83  event.waitUntil(self.registration.showNotification(title, options))
84
85  const count = message.app_badge
86  count ? navigator.setAppBadge(count) : navigator.clearAppBadge()
87})
88
89self.addEventListener('notificationclick', event => {
90  event.notification.close() // Android needs explicit close.
91  let url = event.notification.data.url
92  event.waitUntil(
93    clients.matchAll({type: 'window'}).then(openTabs => {
94      // Check if there is already a tab open with the target URL
95      openTabs.forEach(client => {
96        // if so, just focus it.
97        if (client.url === url) { return client.focus() }
98      })
99      // Otherwise, open the target URL in a new tab
100      clients.openWindow(url)
101    })
102  )
103})

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.