-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathsw.js
34 lines (32 loc) · 1.06 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
var cacheName = "17grePWA-v0.2.3";
var cacheContents = [
"./",
"./index.html",
"./index.js",
"./index.css",
"./lib/vue.global.prod.js"
];
self.addEventListener("install", function(e) {
console.log("[Service Worker] Install");
self.skipWaiting();
e.waitUntil(
caches.open(cacheName).then(function(cache) {
console.log("[Service Worker] Caching contents");
return cache.addAll(cacheContents);
})
);
});
self.addEventListener("fetch", function(e) {
e.respondWith(
caches.match(e.request, { ignoreSearch: true }).then(function(r) {
console.log("[Service Worker] Fetching resouce: " + e.request.url);
return r || fetch(e.request).then(function(response) {
return caches.open(cacheName).then(function(cache) {
console.log("[Service Worker] Caching new resource: " + e.request.url);
cache.put(e.request, response.clone());
return response;
});
});
})
);
});