Skip to content

Commit d582d19

Browse files
committed
Update service-worker.js
1 parent 3e2f20e commit d582d19

File tree

1 file changed

+19
-19
lines changed

1 file changed

+19
-19
lines changed

service-worker.js

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,9 @@ const FILES_TO_CACHE = [
5353

5454
];
5555

56+
57+
// add install and activate event listeners
58+
5659
self.addEventListener('install', (evt) => {
5760

5861
self.skipWaiting();
@@ -63,28 +66,25 @@ self.addEventListener('activate', (evt) => {
6366

6467
self.clients.claim();
6568

66-
// remove previous cached data from disk
67-
evt.waitUntil(
68-
caches.keys().then((keyList) => {
69-
return Promise.all(keyList.map((key) => {
70-
if (key !== WORKER_NAME) {
71-
return caches.delete(key);
72-
}
73-
}));
74-
})
75-
);
76-
77-
// precache static resources
78-
evt.waitUntil(
79-
caches.open(WORKER_NAME).then((cache) => {
80-
return cache.addAll(FILES_TO_CACHE);
81-
})
82-
);
83-
84-
// send message to client
69+
// send install message to client
8570
workerChannel.postMessage({
8671
type: 'installed'
8772
});
8873

8974
});
9075

76+
77+
// remove previous cached data from disk
78+
caches.keys().then((keyList) => {
79+
return Promise.all(keyList.map((key) => {
80+
if (key !== WORKER_NAME) {
81+
return caches.delete(key);
82+
}
83+
}));
84+
});
85+
86+
// precache static resources
87+
caches.open(WORKER_NAME).then((cache) => {
88+
return cache.addAll(FILES_TO_CACHE);
89+
});
90+

0 commit comments

Comments
 (0)