Skip to content

Commit 5fcf98d

Browse files
committed
Update service-worker.js
1 parent 3132ba6 commit 5fcf98d

File tree

1 file changed

+27
-25
lines changed

1 file changed

+27
-25
lines changed

service-worker.js

Lines changed: 27 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
'use strict';
2+
3+
self.importScripts('/worker/client-channel.js');
14

25
// list of files to cache
36
const FILES_TO_CACHE = [
@@ -50,39 +53,38 @@ const FILES_TO_CACHE = [
5053

5154
];
5255

53-
54-
// import service worker/client channel script
55-
self.importScripts('/worker/client-channel.js');
56-
57-
58-
// add install and activate event listeners
59-
6056
self.addEventListener('install', (evt) => {
61-
57+
6258
self.skipWaiting();
6359

6460
});
6561

6662
self.addEventListener('activate', (evt) => {
6763

68-
self.clients.claim();
64+
self.clients.claim();
6965

70-
console.debug('[ServiceWorker] Installed');
71-
72-
});
73-
74-
75-
// remove previous cached data from disk
76-
caches.keys().then((keyList) => {
77-
return Promise.all(keyList.map((key) => {
78-
if (key !== WORKER_NAME) {
79-
return caches.delete(key);
80-
}
81-
}));
82-
});
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 reload request to client
85+
/*workerChannel.postMessage({
86+
type: 'reload'
87+
});*/
8388

84-
// precache static resources
85-
caches.open(WORKER_NAME).then((cache) => {
86-
return cache.addAll(FILES_TO_CACHE);
8789
});
8890

0 commit comments

Comments
 (0)