Skip to content

Commit

Permalink
update service worker once registered, #75061
Browse files Browse the repository at this point in the history
  • Loading branch information
jrieken committed Jul 11, 2019
1 parent e4dd6e8 commit 66ef5b2
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,20 +12,21 @@ declare var self: ServiceWorkerGlobalScope;

//#region --- installing/activating

self.addEventListener('install', event => {
event.waitUntil((async () => {
await caches.delete(_cacheName); // delete caches with each new version
await self.skipWaiting();
}));
self.addEventListener('install', _event => {
console.log('SW#install');
self.skipWaiting();
});

self.addEventListener('activate', event => {
console.log('SW#activate');
event.waitUntil((async () => {
// (1) enable navigation preloads!
// (2) become available to all pages
// (2) delete caches with each new version
// (3) become available to all pages
if (self.registration.navigationPreload) {
await self.registration.navigationPreload.enable();
}
await caches.delete(_cacheName);
await self.clients.claim();
})());
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@ const _serviceWorker = new class ServiceWorkerStarter {
constructor() {
navigator.serviceWorker.register(ServiceWorkerStarter._url, { scope: '/' }).then(reg => {
// console.debug('SW#reg', reg);
return navigator.serviceWorker.ready;
return reg.update();
// }).then(() => {
// // console.debug('SW#updated', reg);
// return navigator.serviceWorker.ready;
}).then(() => {
// console.debug('SW#init');
console.info('SW#ready');
}).catch(err => {
console.error('SW#init', err);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
// statement.

// trigger service worker updates
const _tag = 'c6f6120b-1407-4dd2-84cf-0fe0ef955140';
const _tag = '66399613-d758-4b88-b073-ff4195611d70';

// loader world
const baseUrl = '../../../../../';
Expand Down

0 comments on commit 66ef5b2

Please sign in to comment.