-
Notifications
You must be signed in to change notification settings - Fork 8
/
sw.js
32 lines (28 loc) · 944 Bytes
/
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
const CACHE_NAME = 'cache-v1';
self.addEventListener('install', async function() {
const cache = await caches.open(CACHE_NAME);
cache.addAll([
'/js/deps.js',
'/s/revdict-amis-def.txt',
'/s/revdict-amis-ex.txt',
'/s/stem-words.json',
'/s/index.json'
]);
});
self.addEventListener('fetch', function(event) {
if (event.request.method != 'GET') return;
event.respondWith(async function() {
const cache = await caches.open(CACHE_NAME);
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
event.waitUntil(cache.add(event.request));
return cachedResponse;
}
return fetch(event.request).then(function (response) {
if (response && response.status === 200) {
cache.put(event.target, response.clone());
}
return response;
});
}());
});