question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Service Worker Compilation during Development

See original GitHub issue

Describe the problem

Testing non-trivial service-worker features in a Sveltekit app is currently pretty painful. The most success I’ve had is using npm run build && npm preview after every code change, losing the utility of dev mode when testing features that rely on the service-worker.

As far as I’ve been able to find, Sveltekit only supports building the service-worker in a production build.

Describe the proposed solution

Add a config option to enable building the service-worker in development mode, i.e. when running npm run dev. This should skip pre-caching (or provide a way for the user to skip serving cached files) and only load additional functionality from the user’s service-worker.

Alternatives considered

vite-plugin-pwa appears to support building in development but not for Sveltekit (at least by default, maybe there is a way to configure it to do so?) and also looks like it would add additional configuration to maintain to get it work as well as the built-in SW support.

Importance

would make my life easier

Additional Information

I am currently building/maintaining an app that makes extensive use of the service-worker to enable offline functionality. It hosts a small graphql server at /graphql as a single source of truth for pages to get data from. It is not proxying a “real” graphql server and instead fetches data from multiple places to store in IndexedDB, then queries IDB in the resolvers. It also handles an offline-capable file upload system, uploading files to the server when network service is available.

As a result. most of the app does not work well in dev. Sometimes I can use build-then-preview to get localhost to load the service worker, then stop preview and start dev and the page will start live-loading changes to non-service-worker code but this is flaky; if the SW gets unloaded the app needs to be (possibly rebuilt,) previewed, and swapped back to dev again.

If anyone has an alternative to get SWs working in dev I’d be glad to hear it.

Issue Analytics

  • State:closed
  • Created a year ago
  • Reactions:6
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
Rich-Harriscommented, Jul 13, 2022

Yeah, I definitely think we should support it. I have an idea for how it could work

1reaction
alanxpcommented, Oct 20, 2022

Any news on this? It’s really annoying to develop the service worker without it working on dev mode

Definitely, it is painful having to build, then preview to test a service worker. I’m glad it is labelled with an enhancement tag. But is there any progress with this?

Thanks in advance

Read more comments on GitHub >

github_iconTop Results From Across the Web

Service Worker Compilation during Development #2248
Please describe. The current path for using ESModules for web workers doesn't work for Service Workers, which do not support a the type...
Read more >
Service Worker API - MDN Web Docs
A service worker is run in a worker context: it therefore has no DOM access, and runs on a different thread to the...
Read more >
Create a Service Worker with TypeScript - Dev Extent
In this example, TypeScript is used to create a service worker with a network first then cache, caching strategy, to support viewing previously ......
Read more >
Service worker in production
The service worker responds to requests made by the Angular application for resources or data from a local cache, without needing to wait...
Read more >
Modular Service Worker
Tried to write a webpack plugin that will use the compiler hooks, get access to the compilation object and start a child compiler...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found