-
Notifications
You must be signed in to change notification settings - Fork 6
/
service-worker.js
38 lines (34 loc) · 909 Bytes
/
service-worker.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
const STR_CACHE_NAME = 'site-static';
const assets = [
'/',
'/home',
'/movies',
'/shows',
'/not-found',
'/src/img/not-found/page-not-found.png',
'https://fonts.googleapis.com/css?family=Material+Icons&display=block',
'https://fonts.googleapis.com/css?family=Material+Icons+Outlined&display=block',
'/src/img/favicon'
];
//install service worker
self.addEventListener('install', evt => {
//console.log("service worker has been installed");
evt.waitUntil(
caches.open(STR_CACHE_NAME).then( cache => {
cache.addAll(assets)
})
);
})
//active worker
self.addEventListener('activate', evt => {
//console.log("service worker has been activated");
})
//fetch event listener
self.addEventListener('fetch', evt => {
//console.log('fetch event');
evt.respondWith(
caches.match(evt.request).then( cacheRes => {
return cacheRes || fetch(evt.request);
})
)
})