-
Notifications
You must be signed in to change notification settings - Fork 0
/
regexMulti.sw.js
77 lines (73 loc) · 2.07 KB
/
regexMulti.sw.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
/* globals self, caches, fetch */
const version = 0
const cacheName = 'regexMulti-' + version
const urlsToCache = [
'/index.html',
'/favicon.ico',
'/css/regex-multi.pure.css',
'/css/_particles/variables.css',
'/css/atoms/base.css',
'/css/pages/main-page.css',
'/css/organisms/footer.css',
'/css/organisms/header.css',
'/css/organisms/regex-pair.css',
'/css/organisms/repeatable-description.css',
'/css/organisms/repeatable-extraInputs.css',
'/css/organisms/settings-block.css',
'/css/molecules/alert.css',
'/css/molecules/repeatable-nav.css',
'/css/molecules/tab-nav.css',
'/css/atoms/form-fields.css',
'/css/atoms/helpers.css',
'/css/atoms/lists.css',
'/css/atoms/links.css',
'/css/atoms/screen-reader.css',
'/css/atoms/typeography.css',
'/css/atoms/buttonscheckbox-btn.css',
'/css/atoms/buttonsmain-btn.css',
'/css/atoms/buttonsradio-btn.css',
'/css/atoms/buttonsround-btn.css'
]
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName).then(cache => {
// console.log('urlsToCache:', urlsToCache)
cache.addAll(urlsToCache)
})
)
})
self.addEventListener('activate', event => {
event.waitUntil(
caches.keys().then(cacheNames => {
return Promise.all(
cacheNames.map(name => {
if (name !== cacheName) {
return caches.delete(name)
}
return null
})
)
})
)
})
self.addEventListener('fetch', event => {
event.respondWith(
caches.match(event.request.url).then(response => {
return response || fetch(event.request.url).then(response => {
// Exclude Vite JS requests from cache
if (event.request.url.indexOf('vite') === -1) {
return caches.open(cacheName).then((cache) => {
cache.put(event.request.url, response.clone())
return response
})
} else {
return response
}
}).catch(e => {
console.error('Fetch failed with error: ', e)
})
})
).error(e => {
console.error('respondWith() failed with error: ', e)
})
})