|
| 1 | +'use strict'; |
| 2 | + |
| 3 | +self.importScripts('/worker/client-channel.js'); |
1 | 4 |
|
2 | 5 | // list of files to cache |
3 | 6 | const FILES_TO_CACHE = [ |
@@ -50,39 +53,38 @@ const FILES_TO_CACHE = [ |
50 | 53 |
|
51 | 54 | ]; |
52 | 55 |
|
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 | | - |
60 | 56 | self.addEventListener('install', (evt) => { |
61 | | - |
| 57 | + |
62 | 58 | self.skipWaiting(); |
63 | 59 |
|
64 | 60 | }); |
65 | 61 |
|
66 | 62 | self.addEventListener('activate', (evt) => { |
67 | 63 |
|
68 | | - self.clients.claim(); |
| 64 | + self.clients.claim(); |
69 | 65 |
|
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 | + });*/ |
83 | 88 |
|
84 | | -// precache static resources |
85 | | -caches.open(WORKER_NAME).then((cache) => { |
86 | | - return cache.addAll(FILES_TO_CACHE); |
87 | 89 | }); |
88 | 90 |
|
0 commit comments