-
Notifications
You must be signed in to change notification settings - Fork 3
/
service-worker.js
94 lines (91 loc) · 2.51 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
var APP_PREFIX = 'fantasy-realms-';
var VERSION = '1.0.24';
var CACHE_NAME = APP_PREFIX + VERSION;
var URLS = [
'/',
'index.html',
'manifest.json',
'favicon.ico',
'img/fantasy-realms.jpg',
'img/background.png',
'img/wizkids.png',
'img/globe.png',
'css/style.css',
'css/bootstrap.min.css',
'service-worker.js',
'js/app.js',
'js/deck.js',
'js/hand.js',
'js/bootstrap.bundle.min.js',
'js/handlebars.min-v4.7.7.js',
'js/jquery.i18n.properties.min.js',
'js/jquery-3.6.0.min.js',
'i18n/Messages.properties',
'sound/clear.mp3',
'sound/click.mp3',
'sound/magic.mp3',
'sound/swoosh.mp3',
'browserconfig.xml',
'icons/android-icon-144x144.png',
'icons/android-icon-192x192.png',
'icons/android-icon-36x36.png',
'icons/android-icon-48x48.png',
'icons/android-icon-72x72.png',
'icons/android-icon-96x96.png',
'icons/apple-icon-114x114.png',
'icons/apple-icon-120x120.png',
'icons/apple-icon-144x144.png',
'icons/apple-icon-152x152.png',
'icons/apple-icon-180x180.png',
'icons/apple-icon-57x57.png',
'icons/apple-icon-60x60.png',
'icons/apple-icon-72x72.png',
'icons/apple-icon-76x76.png',
'icons/apple-icon-precomposed.png',
'icons/apple-icon.png',
'icons/favicon-16x16.png',
'icons/favicon-32x32.png',
'icons/favicon-96x96.png',
'icons/ms-icon-144x144.png',
'icons/ms-icon-150x150.png',
'icons/ms-icon-310x310.png',
'icons/ms-icon-70x70.png'
];
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]);
}
}));
})
);
});