-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathservice-worker.js
140 lines (115 loc) · 2.83 KB
/
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
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
"use strict";
// The name of your game, no spaces or special characters.
var name = "Monogatari";
// The version of the cache, changing this will force everything to be cached
// again.
var version = "0.1.1";
var files = [
// General Files
"manifest.json",
// HTML Files
// "index.html",
// Style Sheets
"style/font-awesome.min.css",
"style/kayros.min.css",
"style/animate.min.css",
"style/csshake.min.css",
"style/monogatari.css",
// "style/main.css",
// JavaScript Files
"js/polyfill.min.js",
"js/particles.min.js",
"js/jquery.min.js",
"js/artemis.min.js",
"js/typed.min.js",
"js/monogatari.js",
"js/strings.js",
// "js/options.js",
// "js/storage.js",
// "js/script.js",
// "js/main.js"
// Fonts
"fonts/fontawesome-webfont.eot",
"fonts/fontawesome-webfont.svg",
"fonts/fontawesome-webfont.ttf",
"fonts/fontawesome-webfont.woff",
"fonts/fontawesome-webfont.woff2",
"fonts/FontAwesome.otf",
// App Images
"img/favicon.ico",
"img/icons/icon_48x48.png",
"img/icons/icon_60x60.png",
"img/icons/icon_70x70.png",
"img/icons/icon_76x76.png",
"img/icons/icon_96x96.png",
"img/icons/icon_128x128.png",
"img/icons/icon_150x150.png",
"img/icons/icon_152x152.png",
"img/icons/icon_167x167.png",
"img/icons/icon_180x180.png",
"img/icons/icon_192x192.png",
"img/icons/icon_310x310.png",
"img/icons/icon_512x512.png"
// Scene Images
//"img/scenes/",
// Character Images
//"img/characters/",
// Side Images
//"img/characters/",
// UI Images
//"img/ui/",
// Music Audio
// "audio/music/",
// Voice Audio
// "audio/voice/"
// Sound Audio
// "audio/sound/"
];
self.addEventListener("install", function (event) {
event.waitUntil(
caches.open(`${name}-v${version}`).then(function (cache) {
return cache.addAll(files);
})
);
});
self.addEventListener("activate", function (event) {
event.waitUntil(
caches.keys().then(function (keyList) {
return Promise.all(keyList.map(function (key) {
if (key !== `${name}-v${version}`) {
return caches.delete(key);
}
}));
})
);
return self.clients.claim();
});
self.addEventListener("fetch", function (event) {
if (event.request.method !== "GET") {
return;
}
event.respondWith(
caches.match(event.request).then(function (cached) {
var networked = fetch(event.request)
.then(fetchedFromNetwork, unableToResolve)
.catch(unableToResolve);
return cached || networked;
function fetchedFromNetwork (response) {
var cacheCopy = response.clone();
caches.open(`${name}-v${version}`).then(function add (cache) {
cache.put(event.request, cacheCopy);
});
return response;
}
function unableToResolve () {
return new Response("<h1>Service Unavailable</h1>", {
status: 503,
statusText: "Service Unavailable",
headers: new Headers({
"Content-Type": "text/html"
})
});
}
})
);
});