This repository has been archived by the owner on Apr 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
sw.js
68 lines (59 loc) · 1.52 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
var cache = 'javascripture.20'; // search summary highlighting
self.addEventListener('install', function(e) {
e.waitUntil( caches.open( cache ).then(function(cache) {
return cache.addAll([
'/',
'/index.html',
'/css/layout.css',
'/manifest.json',
'/javascripture.svg',
//libs
'lib/MorphCodes.js',
'lib/MorphParse.js',
//data
'data/bible.js',
'data/extra-dictionary.js',
'data/strongs-dictionary.js',
'data/strongs-greek-dictionary.js',
'data/kjvdwyer7.js',
'data/web3.js',
'data/strongsObjectWithFamilies2.js',
'data/hebrew.js',
'data/greek4.js',
'data/crossReferences.js',
'data/morphology.js',
'data/literalConsistent.js',
'data/literalConsistentExtra.js',
//api - so that search works offline?
'api/searchApi.js',
//modules
'build/bundle.js',
//workers
'workers/worker.js',
]);
}));
});
self.addEventListener('fetch', function(event) {
event.respondWith(
caches.match(event.request).then(function(response) {
return response || fetch(event.request);
})
);
});
// Delete unused cache
self.addEventListener('activate', function( event ) {
const channel = new BroadcastChannel('sw-messages');
channel.addEventListener('message', event => {
channel.postMessage( { versionNumber: cache } );
});
var cacheWhitelist = [ cache ];
event.waitUntil(
caches.keys().then(function( keyList ) {
return Promise.all(keyList.map(function( key ) {
if (cacheWhitelist.indexOf( key ) === -1) {
return caches.delete( key );
}
}));
})
);
});