-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserviceWorker.js
35 lines (31 loc) · 908 Bytes
/
serviceWorker.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
let currentCacheName = 'myGitHub';
let filesToCache = [
'/',
'/index.html',
'/js/main/js',
'/img/AjaxLoader.gif',
'/css/style.css',
'/css/reset.css'
];
self.addEventListener('install', function(e) {
e.waitUntil(
caches.open(currentCacheName).then(function (cache) {
return cache.addAll(filesToCache);
})
.catch(function (err) {
console.log(err)
})
);
});
self.addEventListener('fetch', function(e) {
e.respondWith(
caches.match(e.request).then(function (r) {
return r || fetch(e.request).then(function (response) {
return caches.open(currentCacheName).then(function (cache) {
cache.put(e.request, response.clone());
return response;
});
});
})
);
});