-
Notifications
You must be signed in to change notification settings - Fork 10
/
sw.js
153 lines (142 loc) · 4.41 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
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
141
142
143
144
145
146
147
148
149
150
151
152
153
/*
* grrd's Puzzle
* Copyright (c) 2012 Gerard Tyedmers, [email protected]
* Licensed under the MPL License
*/
/*jslint devel: true, browser: true */ /*global self */
var CACHE_NAME = "grrds-puzzle-cache";
var CACHE_VERSION = "v2.11";
var CACHE = CACHE_NAME + "-" + CACHE_VERSION;
var urlsToCache = [
"index.html",
"Images/4inarow.svg",
"Images/bullets0.svg",
"Images/bullets0o.svg",
"Images/bullets1.svg",
"Images/bullets1o.svg",
"Images/dice.svg",
"Images/down.svg",
"Images/dummy.png",
"Images/easy.svg",
"Images/easy_gold.svg",
"Images/escfullscreen.svg",
"Images/favicon.ico",
"Images/favicon_dark.ico",
"Images/fullscreen.svg",
"Images/hard.svg",
"Images/hard_gold.svg",
"Images/info.svg",
"Images/loading.svg",
"Images/lock.svg",
"Images/mail.svg",
"Images/medal1.svg",
"Images/medal2.svg",
"Images/medal3.svg",
"Images/medium.svg",
"Images/medium_gold.svg",
"Images/memo.svg",
"Images/next.svg",
"Images/ok.svg",
"Images/photo.svg",
"Images/piece_gold.svg",
"Images/prev.svg",
"Images/puzzle.svg",
"Images/settings.svg",
"Images/tictactoe.svg",
"Images/title1.png",
"Images/title_wide.png",
"Images/x.svg",
"Images/africa/theme.png",
"Images/america/theme.png",
"Images/animals/theme.png",
"Images/asia/theme.png",
"Images/europe/theme.png",
"Images/flowers/theme.png",
"Images/mascha/theme.png",
"Images/mascha2/theme.png",
"Images/mascha3/theme.png",
"Images/mascha4/theme.png",
"Images/tricky/theme.png",
"Scripts/exif.js",
"Scripts/kinetic-v4.7.4.min.js",
"Scripts/l10n.js",
"Scripts/puzzle.css",
"Scripts/puzzle.js",
"Scripts/swipe.css",
"Scripts/swipe.js",
"Locales/ar/puzzle.properties",
"Locales/bn/puzzle.properties",
"Locales/cs/puzzle.properties",
"Locales/de/puzzle.properties",
"Locales/en/puzzle.properties",
"Locales/es/puzzle.properties",
"Locales/fr/puzzle.properties",
"Locales/hr/puzzle.properties",
"Locales/hu/puzzle.properties",
"Locales/it/puzzle.properties",
"Locales/nl/puzzle.properties",
"Locales/pl/puzzle.properties",
"Locales/pt_BR/puzzle.properties",
"Locales/pt_PT/puzzle.properties",
"Locales/rm/puzzle.properties",
"Locales/ru/puzzle.properties",
"Locales/sl/puzzle.properties",
"Locales/sr/puzzle.properties",
"Locales/ta/puzzle.properties",
"Locales/tr/puzzle.properties",
"Locales/ur/puzzle.properties",
"Locales/zh/puzzle.properties",
"Locales/zh_CN/puzzle.properties",
"Locales/locales.ini",
"Sounds/click.mp3",
"Sounds/click.ogg",
"Sounds/ding.mp3",
"Sounds/ding.ogg"
];
self.addEventListener("install", function (event) {
// Perform install steps
event.waitUntil(
caches.open(CACHE)
.then(function (cache) {
return cache.addAll(urlsToCache);
})
);
});
self.addEventListener("fetch", function (event) {
event.respondWith(
caches.match(event.request)
.then(function (response) {
// Cache hit - return response
if (response) {
return response;
}
var fetchRequest = event.request.clone();
return fetch(fetchRequest).then(
function (response) {
// Check if we received a valid response
if (!response || response.status !== 200 || response.type !== "basic") {
return response;
}
var responseToCache = response.clone();
caches.open(CACHE)
.then(function (cache) {
cache.put(event.request, responseToCache);
});
return response;
}
);
})
);
});
self.addEventListener("activate", function (event) {
event.waitUntil(
caches.keys().then(function (cacheNames) {
return Promise.all(cacheNames.map(function (cacheName) {
if (cacheName.indexOf(CACHE_NAME) === 0 && cacheName.indexOf(CACHE_VERSION) === -1) {
console.log(cacheName + " deleted");
return caches.delete(cacheName);
}
}));
})
);
});