-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
52 lines (46 loc) · 1.23 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
// Copyright 2018 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
// @ts-check
'use strict';
const cacheName = 'd645fde81e1044e8a9c4b0402673730e';
const filesToCache = [
'favicon.ico',
'index.html',
'infocard-ui.js',
'infocard.css',
'main.css',
'manifest.json',
'options.css',
'shared.js',
'start-worker.js',
'state.js',
'tree-ui.js',
'tree-worker.js',
];
// On install, cache the items in the `filesToCache` list
self.addEventListener('install', event => {
event.waitUntil(
caches.open(cacheName).then(cache => cache.addAll(filesToCache))
);
});
// On activate, remove any old caches
self.addEventListener('activate', event => {
async function deleteOldCache(key) {
if (key !== cacheName) {
return caches.delete(key);
}
}
event.waitUntil(
caches.keys().then(keyList => Promise.all(keyList.map(deleteOldCache)))
);
return self.clients.claim();
});
// On fetch, return entries from the cache if possible
self.addEventListener('fetch', event => {
event.respondWith(
caches
.match(event.request, {ignoreSearch: true})
.then(response => response || fetch(event.request))
);
});