I have a service-worker that support my page for work offline On firefox every time I change page or reload it, a new install event is triggered on the service-worker. useless say I don't want it to happen, also, by specifics, it should not happen... and on chrome, I have a predictable and coherent behavior
I have another service-worker that run in place of the main on certain circumstances, is pretty much empty, but that one isn't reinstalled everytime, I have the console.log to prove it
the installation from client is pretty simple
console.log('[Client] start register');
await navigator.serviceWorker.register(scriptpath.js)
on the main SW i have the standard eventlistener:
var foo = undefined;
var bar = false;
self.addEventListener('install', evt=>{
console.log('[MainWorker] install');
evt.waitUntil(
self.skipWaiting()
);
});
self.addEventListener('activate', evt=>{
console.log('[MainWorker] activated!');
evt.waitUntil(
initializeVars(),
self.clients.claim()
);
});
...other things like fetch and message
this code is on the secondary SW
var Test = false;
self.addEventListener('install', evt=>{
console.log('[SecondaryWorker] install');
evt.waitUntil(
self.skipWaiting()
);
});
self.addEventListener('activate', evt=>{
console.log('[SecondaryWorker] activated!');
Test = true;
evt.waitUntil(
self.clients.claim()
);
});
but no matter what, the main service-worker is reinstalled every time, the other one no.
per se, I can accept it, if it is not the fact that I have some variable on the main sw that I change via message, and every time is reinstalled they are, obviously, lost