PageSourceSearch

https://cimre.ca/sw.js

js cimre.ca collected 2026-10-04 19:52:36 UTC 6,114 bytes, 150 lines download raw bytes

1"use strict";
2
3const CACHE_NAME = 'cimre.ca-1618252319370';
4const SW_SUPPORTED_PROTOCOL_REGEX = /http(s?):/;
5const pageUrls = JSON.parse('["/"]');
6const staticAssets = JSON.parse('["//img1.wsimg.com/blobby/go/41978683-ebe4-491d-b565-c744e970d843/gpub/f0cf65d65ab4f02c/script.js","//img1.wsimg.com/ceph-p3-01/website-builder-data-prod/static/widgets/UX.4.8.3.js","//fonts.googleapis.com/css?family=Montserrat:600,700&display=swap","//fonts.googleapis.com/css?family=Roboto:100,300,300i,400,400i,700,700i,900&display=swap"]');
7const networkOnlyUrls = JSON.parse('["https://api.ola.godaddy.com","https://41978683-ebe4-491d-b565-c744e970d843.onlinestore.godaddy.com","https://img.secureserver.net/t/1/tl/event","https://img.test-secureserver.net/t/1/tl/event","https://www.google-analytics.com/collect","https://calendar.apps.dev-secureserver.net","https://calendar.apps.test-secureserver.net","https://calendar.apps.secureserver.net"]');
8const networkOnlyUrlsRegex = JSON.parse('["cimre.ca/m/api/.*","cimre.ca(?:/.*)?/ola/services/.*","cimre.ca/ola/meetings/.*","cimre.ca/g/api/.*","
8securepay.godaddy.com/api/apps/ola/accounts/.*"]').map(regexString => new RegExp(regexString));
9const networkThenCacheUrls = JSON.parse('["https://blog.apps.secureserver.net/v1/website/41978683-ebe4-491d-b565-c744e970d843/feed/post/","https://blog.apps.secureserver.net/v1/website/41978683-ebe4-491d-b565-c744e970d843/feed"]');
10const networkThenCacheUrlsRegex = JSON.parse('["cimre.ca(?:/.*)?/f/.*"]').map(regexString => new RegExp(regexString));
11self.addEventListener('unhandledrejection', function (event) {
12  // eslint-disable-next-line no-console
13  console.warn('sw unhandledrejection error: ', event.reason);
14});
15
16function preCacheResources() {
17  return caches.open(CACHE_NAME).then(function (cache) {
18    // Pre-Cache pages to improve subsequent navigation but don't making it blocking
19    // Avoid extremely large websites from using the end-users data in unexpected amount
20    cache.addAll(pageUrls); // Pre-cache all static assets by keeping them as installation dependency
21
22    return cache.addAll(staticAssets);
23  });
24}
25
26self.addEventListener('install', function (event) {
27  // Let the new worker take over as fast as possible
28  // For quirks refer: https://developers.google.com/web/fundamentals/primers/service-workers/lifecycle#skip_the_waiting_phase
29  self.skipWaiting();
30  event.waitUntil(preCacheResources());
31});
32
33function clearOldCache() {
34  return caches.keys().then(function (keys) {
35    return Promise.all(keys.filter(function (key) {
36      return key !== CACHE_NAME;
37    }).map(function (key) {
38      return caches.delete(key);
39    }));
40  });
41}
42
43self.addEventListener('activate', function (event) {
44  // Remember to keep this step as lean as possible
45  // Only sutiable for performing stuff that can't be done while the previous worker is running
46  event.waitUntil(clearOldCache().then(function () {
47    clients.claim(); // eslint-disable-line no-undef
48  }));
49});
50
51function isPageRequest(url) {
52  return url.origin === location.origin && pageUrls.includes(url.pathname);
53}
54
55function isNetworkOnlyRequest(url, requestMethod) {
56  // Browser extensions don't use the standard `http` and `https` protocols
57  // Refer: https://github.com/GoogleChromeLabs/sw-toolbox/issues/171
58  if (requestMethod !== 'GET' || !SW_SUPPORTED_PROTOCOL_REGEX.test(url.protocol)) {
59    return true;
60  }
61
62  const urlOrigin = url.origin;
63  const urlPathName = url.pathname;
64  const fullUrl = `${urlOrigin}${urlPathName}`;
65
66  if (networkOnlyUrls.includes(urlOrigin) || networkOnlyUrls.includes(fullUrl)) {
67    return true;
68  }
69
70  if (networkOnlyUrlsRegex.some(regex => regex.test(fullUrl))) {
71    return true;
72  }
73
74  return false;
75}
76
77function isNetworkThenCacheRequest(url, requestMethod) {
78  // Browser extensions don't use the standard `http` and `https` protocols
79  // Refer: https://github.com/GoogleChromeLabs/sw-toolbox/issues/171
80  if (requestMethod !== 'GET' || !SW_SUPPORTED_PROTOCOL_REGEX.test(url.protocol)) {
81    return true;
82  }
83
84  const urlOrigin = url.origin;
85  const urlPathName = url.pathname;
86  const fullUrl = `${urlOrigin}${urlPathName}`;
87
88  if (networkThenCacheUrls.includes(urlOrigin) || networkThenCacheUrls.includes(fullUrl)) {
89    return true;
90  }
91
92  if (networkThenCacheUrlsRegex.some(regex => regex.test(fullUrl))) {
93    return true;
94  }
95
96  return false;
97}
98
99function handleWithNetworkThenCache(event) {
100  return event.respondWith(fetch(event.request).then(function (networkResponse) {
101    if (!networkResponse.ok) {
102      return networkResponse;
103    }
104
105    return caches.open(CACHE_NAME).then(function (cache) {
106      cache.put(event.request, networkResponse.clone());
107      return networkResponse;
108    });
109  }).catch(function () {
110    // network failed, try to serve a cached response or offline page if there is one
111    return caches.match(event.request);
112  }));
113}
114
115function handleWithCacheThenNetwork(event) {
116  return event.respondWith(caches.open(CACHE_NAME).then(function (cache) {
117    return cache.match(event.request).then(function (response) {
118      return response || fetch(event.request).then(function (networkResponse) {
119        networkResponse.ok && cache.put(event.request, networkResponse.clone());
120        return networkResponse;
121      });
122    });
123  }).catch(function (err) {
124    // TODO: respond with `offline.html` as the final fallback for page requests
125    // and use appropriate response for other cases
126    return err;
127  }));
128}
129
130function handleWithNetwork(event) {
131  return event.respondWith(fetch(event.request));
132}
133
134function handleRequests(event) {
135  const requestURL = new URL(event.request.url);
136
137  if (isNetworkOnlyRequest(requestURL, event.request.method)) {
138    return handleWithNetwork(event);
139  }
140
141  if (isPageRequest(requestURL) || isNetworkThenCacheRequest(requestURL, event.request.method)) {
142    // To avoid serving stale content after a publish
143    // always fetch the markup from origin and use cache only when the user is offline
144    return handleWithNetworkThenCache(event);
145  }
146
147  return handleWithCacheThenNetwork(event);
148}
149
150self.addEventListener('fetch', handleRequests);

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.