-
Notifications
You must be signed in to change notification settings - Fork 2
/
sw.js
120 lines (115 loc) · 2.81 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
'use strict';
const appCaches = [
{
name: 'core-20240601.01',
urls: [
'/',
'/bundle.js',
'/favicon.png',
'/help/about.html',
'/icons.svg',
'/index.html',
'/js/load.js',
'/js/progress.js',
'/manifest.json',
'/robots.txt',
]
},
{
name: 'css-20240512.01',
urls: [
'/css/kjv.css',
'/css/font.css',
]
},
{
name: 'font-20240512.01',
urls: [
'/font/courgette-v17-latin-regular.woff2',
'/font/inconsolata-v32-latin-regular.woff2',
'/font/merienda-v19-latin-regular.woff2',
'/font/merriweather-v30-latin-regular.woff2',
'/font/noto-serif-hebrew-v25-latin-regular.woff2',
'/font/open-sans-v40-latin-regular.woff2',
'/font/roboto-mono-v23-latin-regular.woff2',
'/font/roboto-slab-v34-latin-regular.woff2',
'/font/roboto-v30-latin-regular.woff2',
]
},
{
name: 'help-20240516.02',
urls: [
'/help/bookmark.html',
'/help/clipboard-mode.html',
'/help/help.html',
'/help/navigator.html',
'/help/overview.html',
'/help/read.html',
'/help/search.html',
'/help/setting.html',
'/help/thats-my-king.html',
'/help/the-acts-of-peter.html',
]
},
{
name: 'json-20240512.01',
urls: [
'/json/kjv_lists.json',
'/json/kjv_pure.json',
]
},
{
name: 'png-20240516.01',
urls: [
'/png/icon-032.png',
'/png/icon-192.png',
'/png/icon-512.png',
'/png/maskable-icon-192.png',
'/png/maskable-icon-512.png',
],
},
{
name: 'webp-20240516.01',
urls: [
'/webp/android.webp',
'/webp/desktop.webp',
],
},
];
const cacheNames = appCaches.map((cache) => cache.name);
self.addEventListener('install', (event) => {
event.waitUntil(caches.keys().then((keys) => {
return Promise.all(appCaches.map(async (appCache) => {
if (keys.indexOf(appCache.name) === -1) {
const cache = await caches.open(appCache.name);
console.log(`Caching: ${appCache.name}`);
return await cache.addAll(appCache.urls);
} else {
console.log(`Found: ${appCache.name}`);
return Promise.resolve(true);
}
}));
}));
self.skipWaiting();
});
self.addEventListener('activate', (event) => {
event.waitUntil(
caches.keys().then((keys) => {
return Promise.all(keys.map((key) => {
if (cacheNames.indexOf(key) === -1) {
console.log(`Deleting: ${key}`);
return caches.delete(key);
}
}));
})
);
self.clients.claim();
});
self.addEventListener('fetch', (event) => {
event.respondWith(
caches.match(event.request).then((response) => response ||
fetch(event.request).then((response) => response)).catch((error) => {
console.log('Fetch failed:', error);
})
);
});