-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
74 lines (71 loc) · 2.21 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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
var GHPATH = "/potato-peace";
var APP_PREFIX = "peace_";
var VERSION = "version_0.08";
var URLS = [
`${GHPATH}/`,
`${GHPATH}/index.html`,
`${GHPATH}/manifest.webmanifest`,
`${GHPATH}/script.js`,
`${GHPATH}/vn-runner.js`,
`${GHPATH}/ink.js`,
`${GHPATH}/story.js`,
`${GHPATH}/style.css`,
`${GHPATH}/img/about.png`,
`${GHPATH}/img/ceremony.png`,
`${GHPATH}/img/cover.png`,
`${GHPATH}/img/father.png`,
`${GHPATH}/img/mayor.png`,
`${GHPATH}/img/mc.png`,
`${GHPATH}/img/mc2.png`,
`${GHPATH}/img/mc3.png`,
`${GHPATH}/img/museum.png`,
`${GHPATH}/img/office.png`,
`${GHPATH}/img/restart.png`,
`${GHPATH}/img/save.png`,
`${GHPATH}/img/sculptor.png`,
`${GHPATH}/img/statue.png`,
`${GHPATH}/img/theme.png`,
`${GHPATH}/img/town.png`,
`${GHPATH}/img/woods.png`
];
var CACHE_NAME = APP_PREFIX + VERSION;
self.addEventListener("fetch", function (e) {
console.log("Fetch request : " + e.request.url);
e.respondWith(
caches.match(e.request).then(function (request) {
if (request) {
console.log("Responding with cache : " + e.request.url);
return request;
} else {
console.log("File is not cached, fetching : " + e.request.url);
return fetch(e.request);
}
})
);
});
self.addEventListener("install", function (e) {
e.waitUntil(
caches.open(CACHE_NAME).then(function (cache) {
console.log("Installing cache : " + CACHE_NAME);
return cache.addAll(URLS);
})
);
});
self.addEventListener("activate", function (e) {
e.waitUntil(
caches.keys().then(function (keyList) {
var cacheWhitelist = keyList.filter(function (key) {
return key.indexOf(APP_PREFIX);
});
cacheWhitelist.push(CACHE_NAME);
return Promise.all(
keyList.map(function (key, i) {
if (cacheWhitelist.indexOf(key) === -1) {
console.log("Deleting cache : " + keyList[i]);
return caches.delete(keyList[i]);
}
})
);
})
);
});