Skip to content

Commit bcfa7c3

Browse files
committed
Update service-worker.js
1 parent 4e7044c commit bcfa7c3

File tree

1 file changed

+17
-28
lines changed

1 file changed

+17
-28
lines changed

service-worker.js

Lines changed: 17 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -59,38 +59,27 @@ const FILES_TO_CACHE = [
5959

6060
];
6161

62+
63+
// remove previous cached data
64+
caches.keys().then((keyList) => {
65+
return Promise.all(keyList.map((key) => {
66+
if (key !== WORKER_NAME) {
67+
return caches.delete(key);
68+
}
69+
}));
70+
});
71+
72+
// precache static resources
73+
caches.open(WORKER_NAME).then((cache) => {
74+
return cache.addAll(FILES_TO_CACHE);
75+
});
76+
77+
6278
self.addEventListener('install', (evt) => {
63-
6479
self.skipWaiting();
65-
6680
});
6781

6882
self.addEventListener('activate', (evt) => {
69-
70-
self.clients.claim();
71-
72-
// remove previous cached data from disk
73-
evt.waitUntil(
74-
caches.keys().then((keyList) => {
75-
return Promise.all(keyList.map((key) => {
76-
if (key !== WORKER_NAME) {
77-
return caches.delete(key);
78-
}
79-
}));
80-
})
81-
);
82-
83-
// precache static resources
84-
evt.waitUntil(
85-
caches.open(WORKER_NAME).then((cache) => {
86-
return cache.addAll(FILES_TO_CACHE);
87-
})
88-
);
89-
90-
// send reload request to client
91-
/*workerChannel.postMessage({
92-
type: 'reload'
93-
});*/
94-
83+
self.clients.claim();
9584
});
9685

0 commit comments

Comments
 (0)