-
Notifications
You must be signed in to change notification settings - Fork 8
/
sw.js
87 lines (82 loc) · 2.77 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
/*
Service Worker to enable the webpage to be used even offline, once installed
Cached site should require only ~ 3 MB space
*/
const CURRENT_CACHE_VERSION = 'mapart-cache-5.3.0';
const CACHE_URLS_LOCAL = [
/* Important : `/` doesn't automatically fetch `/index.html` locally, explicitly cache it
This file *must* be placed at the top-level of the repository, no subfolder
Paths are also relative to its location. */
'./',
'index.html',
'manual.html',
'about.html',
'site.webmanifest',
'LICENSE.txt',
'css/style.css',
'css/style-dark.css',
'resources/Minecraft-Regular.otf',
'resources/sample_pack.mcpack',
'images/headercover.png',
'images/favicon.ico',
'images/logo_128px.png',
'images/d1.png',
'images/d2.png',
'images/d3.png',
'images/d4.png',
'images/d5.png',
'images/layout_big.png',
'images/android-chrome-192x192.png',
'images/android-chrome-512x512.png',
'images/apple-touch-icon.png',
'images/safari-pinned-tab.svg',
'images/mstile-150x150.png',
'images/favicon-32x32.png',
'images/favicon-16x16.png',
'images/browserconfig.xml',
'scripts/data.js',
'scripts/templates.js',
'scripts/main.js',
'scripts/imageProcessor.js',
'scripts/functionWriter.js',
'scripts/localStorage.js',
'scripts/theme_pwa.js',
];
const CACHE_URLS_EXTERNAL = [
'https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/jquery.slim.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/umd/popper.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/jszip/3.5.0/jszip.min.js',
'https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.0/FileSaver.min.js',
'https://cdn.jsdelivr.net/npm/[email protected]/ejs.min.js',
];
self.addEventListener('install', function(event) {
event.waitUntil(
caches.open(CURRENT_CACHE_VERSION)
.then(function(cache) {
cache.addAll(CACHE_URLS_EXTERNAL);
return cache.addAll(CACHE_URLS_LOCAL);
})
);
});
self.addEventListener('activate', function (event) {
event.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(
cacheName => (cacheName !== CURRENT_CACHE_VERSION)
).map(function(cacheName) {
return caches.delete(cacheName);
})
);
})
);
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});