"Claim" the Service Worker as soon as it is activated, so that it can

be triggered right away (without the need to reload the page or app).
Fixes #129
This commit is contained in:
mossroy 2016-01-04 11:39:28 +01:00
parent 4bcf287835
commit 15a4c04e62

View File

@ -52,6 +52,19 @@ function b64toBlob(b64Data, contentType, sliceSize) {
return blob;
}
self.addEventListener('install', function(event) {
event.waitUntil(self.skipWaiting());
console.log("ServiceWorker installed");
});
self.addEventListener('activate', function(event) {
// "Claiming" the ServiceWorker is necessary to make it work right away,
// without the need to reload the page.
// See https://developer.mozilla.org/en-US/docs/Web/API/Clients/claim
event.waitUntil(self.clients.claim());
console.log("ServiceWorker activated");
});
require({
baseUrl: "./www/js/lib/"
},
@ -62,14 +75,6 @@ function(util) {
console.log("ServiceWorker startup");
var outgoingMessagePort = null;
self.addEventListener('install', function(event) {
console.log("ServiceWorker installed");
});
self.addEventListener('activate', function(event) {
console.log("ServiceWorker activated");
});
self.addEventListener('message', function (event) {
if (event.data.action === 'init') {
@ -177,4 +182,4 @@ function(util) {
// then the default request/response behavior will automatically be used.
});
});
});