-
Notifications
You must be signed in to change notification settings - Fork 0
/
sw.js
84 lines (73 loc) · 2.19 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
const cacheVersion = 8;
var appCache = 'calendar-v'+cacheVersion;
var appFiles = [
'/',
'/index.html',
'/manifest.webmanifest',
'/icon/app-icon.png',
'/icon/app-icon.svg',
'/icon/favicon.png',
'/icon/touch-icon.png',
'/scripts/conversion.min.js',
'/scripts/calendar.min.js',
'/scripts/computus.min.js',
'/scripts/app.min.js',
'/scripts/jquery.min.js',
'/i18n/jquery.i18n.js',
'/i18n/jquery.i18n.emitter.js',
'/i18n/jquery.i18n.fallbacks.js',
'/i18n/jquery.i18n.messagestore.js',
'/i18n/jquery.i18n.parser.js',
'/i18n/languages/am-eth.json',
'/i18n/languages/am-lat.json',
'/i18n/languages/en.json',
'/i18n/languages/fr.json',
'/i18n/languages/gez-eth.json',
'/i18n/languages/gez-lat.json',
'/i18n/languages/om.json',
'/i18n/languages/pl.json',
'/i18n/languages/ti-eth.json',
'/i18n/languages/ti-lat.json',
'/styles/style.css',
'/styles/notosans/NotoSansEthiopic-Bold.woff2',
'/styles/notosans/NotoSansEthiopic.woff2',
'/styles/notosans/notosans.min.css',
'/styles/octicons/octicons.min.css',
'/styles/octicons/octicons.woff2?ef21c39f0ca9b1b5116e5eb7ac5eabe6'
];
self.addEventListener('install', (e) => {
e.waitUntil(
caches.open(appCache).then((cache) => {
console.log('[Service Worker] Installing new cache: '+appCache);
return cache.addAll(appFiles);
})
);
});
self.addEventListener('fetch', (e) => {
e.respondWith(
caches.match(e.request).then((r) => {
return r || fetch(e.request).then((response) => {
return caches.open(appCache).then((cache) => {
console.log('[Service Worker] Caching new resource: '+e.request.url);
cache.put(e.request, response.clone());
return response;
});
});
})
);
});
self.addEventListener('activate', (e) => {
console.log('[Service Worker] Activated');
e.waitUntil(
caches.keys().then(function(cacheNames) {
return Promise.all(
cacheNames.filter(function(cacheName) {
return parseInt(cacheName.substr(10)) < cacheVersion
}).map(function(cacheName) {
console.log('[Service Worker] Deleting cache: '+cacheName);
return caches.delete(cacheName);
})
);
})
);
});