-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsw.js
44 lines (41 loc) · 1.57 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
const CACHE_NAME = `cache-混音助手`;
// Use the install event to pre-cache all initial resources.
self.addEventListener('install', event => {
event.waitUntil((async () => {
const cache = await caches.open(CACHE_NAME);
cache.addAll([
'/',
'/index.html',
'/favicon.ico',
'/avatar.jpg',
'/bg.jpeg',
'/detect-bpm.js',
'//cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css',
'//cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js',
'//www.googletagmanager.com/gtag/js?id=G-HNJVWCDF58',
'//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-4648087201834829'
]);
})());
});
self.addEventListener('fetch', event => {
event.respondWith((async () => {
const cache = await caches.open(CACHE_NAME);
// Get the resource from the cache.
const cachedResponse = await cache.match(event.request);
if (cachedResponse) {
return cachedResponse;
} else {
try {
// If the resource was not in the cache, try the network.
const fetchResponse = await fetch(event.request);
console.dir(cache);
// Save the resource in the cache and return it.
cache.put(event.request, fetchResponse.clone());
return fetchResponse;
} catch (e) {
console.log(e);
// The network failed.
}
}
})());
});