简体   繁体   中英

Workbox: when there is a new service worker, it loads but waits

I work on Windows Pro 10 and use Workbox 6.x. As a test, in Chrome:

  • I load my site
  • Create a local app on the desktop
  • Start the app
  • Press F12 for DevTools
  • Check Offline
  • Change one of the file and rebuild the site
  • Publish the site
  • Check off Offline

What I would like is the updated service worker get activated right away, but DevTools says it is waiting.

Documentation says that by default this will be added to the service worker:

 self.addEventListener('message', event => { if (event.data && event.data.type === 'SKIP_WAITING') { self.skipWaiting(); }

I check and indeed the code is added,

Why then isn't skipWaiting doing the job?

Thanks,

Gilles Plante

Are you using workbox-build generateSW to generate your service worker? Because by default skipWaiting is set to false. You can check it here in the docstring , and here in the defaults .

If you just want to skip the service worker waiting state when you are developing, you can enable Update on Reload in Chrome Dev Tools.

重新加载更新

Also, be aware of the dangers of skipWaiting() .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM