Skip to content

HMR for Service Worker without PWA #692

Answered by richardsimko
richardsimko asked this question in Q&A
Discussion options

You must be logged in to vote
if ('serviceWorker' in navigator) {
    const reg = await navigator.serviceWorker.register(import.meta.env.MODE === 'production' ? '/service-worker.js' : '/bundle/dev-sw.js?dev-sw', {
      type: import.meta.env.MODE === 'production' ? 'classic' : 'module',
    });
    await reg.update();
  }

It seems the missing piece of the puzzle was calling update after the worker has been registered.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by richardsimko
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant