This repository has been archived by the owner on Sep 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
sw.js
58 lines (55 loc) · 1.76 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
/* eslint-disable */
// service-worker.js
workbox.core.setCacheNameDetails({ prefix: 'd4' });
//Change this value every time before you build
const LATEST_VERSION = 'v2.0.12';
self.addEventListener('activate', (event) => {
console.log(`%c ${LATEST_VERSION} `, 'background: #ddd; color: #0000ff');
if (caches) {
caches.keys().then((arr) => {
arr.forEach((key) => {
if (key.indexOf('d4-precache') < -1) {
caches
.delete(key)
.then(() =>
console.log(
`%c Cleared ${key}`,
'background: #333; color: #ff0000',
),
);
} else {
caches.open(key).then((cache) => {
cache.match('version').then((res) => {
if (!res) {
cache.put(
'version',
new Response(LATEST_VERSION, {
status: 200,
statusText: LATEST_VERSION,
}),
);
} else if (res.statusText !== LATEST_VERSION) {
caches
.delete(key)
.then(() =>
console.log(
`%c Cleared Cache ${LATEST_VERSION}`,
'background: #333; color: #ff0000',
),
);
} else
console.log(
`%c Great you have the latest version ${LATEST_VERSION}`,
'background: #333; color: #00ff00',
);
});
});
}
});
});
}
});
workbox.core.skipWaiting();
workbox.core.clientsClaim();
self.__precacheManifest = [].concat(self.__precacheManifest || []);
workbox.precaching.precacheAndRoute(self.__precacheManifest, {});