-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
31 lines (28 loc) · 761 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
var cacheName = 'hello-pwa';
var filesToCache = [
'./',
'./index.html',
'./css/style.css',
'./js/index.js',
'./images/charging.png'
];
/* Start the service worker and cache all of the app's content */
self.addEventListener('install', function(e) {
console.log("install - before wait");
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log("install - in open");
return cache.addAll(filesToCache);
})
);
});
/* Serve cached content when offline */
//map will not work while offline
self.addEventListener('fetch', function(event) {
console.log(event.request.url);
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});