-
Notifications
You must be signed in to change notification settings - Fork 1
/
sw.js
41 lines (38 loc) · 1.31 KB
/
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
// use a cacheName for cache versioning
var cacheName = 'v1:static';
self.addEventListener('beforeinstallprompt', function(e) {
// TO DO
});
// during the install phase you usually want to cache static assets
self.addEventListener('install', function(e) {
// once the SW is installed, go ahead and fetch the resources to make this work offline
e.waitUntil(
caches.open(cacheName).then(async function(cache) {
await cache.addAll([
'./',
'./cv/',
'./asset-store/',
'./vendor/jquery/jquery-3.4.1.min.js',
'./vendor/bootstrap/js/bootstrap.min.js',
'./vendor/bootstrap/css/bootstrap.min.css',
'./vendor/font-awesome/css/font-awesome.min.css',
'./style.css',
]);
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);
})
);
});