-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
33 lines (31 loc) · 943 Bytes
/
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
// Use a cacheName for cache versioning
var cacheName = 'v4:static'
// During the installation phase, you'll usually want to cache static assets.
self.addEventListener('install', function (e) {
// Once the service worker is installed, go ahead and fetch the resources to make this work offline.
e.waitUntil(
caches.open(cacheName).then(function (cache) {
return cache.addAll([
'./',
'./css/main.css',
'./js/site.js'
]).then(function () {
self.skipWaiting()
})
})
)
})
// when the browser fetches a URL…
self.addEventListener('fetch', function (event) {
// … either respond with the cached object or go ahead and fetch the actual URL
event.respondWith(
caches.match(event.request).then(function (response) {
if (response) {
// retrieve from cache
return response
}
// fetch as normal
return fetch(event.request)
})
)
})