1

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

recnac
  • 3,744
  • 6
  • 24
  • 46
Zoronel
  • 35
  • 6
  • _per se, i can accept it, if 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_ makes me think that you're misunderstanding how global state works in a service worker. Does the info at https://stackoverflow.com/a/38835274/385997 help clear that up? – Jeff Posnick May 01 '19 at 18:55
  • @JeffPosnick . Honestly, yes, and with that post i can "fix" the problem, but still the fact that my "SW" trigger "install" event even without a new version is provided. and i know that for sure because i have the log – Zoronel May 03 '19 at 07:23

0 Answers0