Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

371
Views
Is there a way to implement "update service worker on reload"?

I understand that when you reload a tab, the waiting service worker won't be activated, because the previous tab and new tab are overlapped.

But I am wondering if there is a way to implement it by delaying the closing of the old tab or opening of the new tab, such that we can skip waiting and activate the waiting service worker?

I tried this:

    const wb = new Workbox("service-worker.js");
    wb.addEventListener("waiting", () => {
      window.addEventListener('beforeunload', async () => {
        await wb.messageSkipWaiting();
      });
    });

And it does activate the waiting service worker on reload, but the reload sometimes hangs forever, because there is race condition that reloading needs to fetch index.html and assets from the service worker, while the activation of service worker might interrupt the request. For example, if the old SW was handling the request, and suddenly it is replaced by the new SW, the request could hang.

Not sure if there is a better to handle this.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!