Skip to content

Commit da9843e

Browse files
committed
Fixed: Rename Cache Name to prevent potential mis-deletion from other apps
1 parent 8b4cb09 commit da9843e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

sw.js

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,13 @@
66
* Register service worker.
77
* ========================================================== */
88

9-
const PRECACHE = 'precache-v1';
10-
const RUNTIME = 'runtime';
9+
// CACHE_NAMESPACE
10+
// CacheStorage is shared between all sites under same domain.
11+
// A namespace can prevent potential name conflicts and mis-deletion.
12+
const CACHE_NAMESPACE = 'main-'
13+
14+
const PRECACHE = CACHE_NAMESPACE + 'precache-v1';
15+
const RUNTIME = CACHE_NAMESPACE + 'runtime';
1116
const HOSTNAME_WHITELIST = [
1217
self.location.hostname,
1318
"huangxuan.me",
@@ -94,6 +99,7 @@ self.addEventListener('install', e => {
9499
* waitUntil(): activating ====> activated
95100
*/
96101
self.addEventListener('activate', event => {
102+
// TODO: consider some cleanning up.
97103
console.log('service worker activated.')
98104
event.waitUntil(self.clients.claim());
99105
});

0 commit comments

Comments
 (0)