-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsw.js
More file actions
30 lines (29 loc) · 915 Bytes
/
sw.js
File metadata and controls
30 lines (29 loc) · 915 Bytes
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
self.addEventListener('install', (event) => {
event.waitUntil(
caches.open('redirector-cache').then((cache) => {
return cache.addAll([
'index.html',
'css/style.css',
'img/favicon.png',
'js/app.js',
'js/redirector.js',
'js/config.js'
])
})
)
})
self.addEventListener('fetch', (event) => {
event.respondWith(caches.match(event.request).then((response) => {
if (response !== undefined) {
return response
} else {
return fetch(event.request).then((response) => {
let responseClone = response.clone()
caches.open('redirector-cache').then((cache) => {
cache.put(event.request, responseClone)
})
return response;
})
}
}))
})