0

I'm interested in running background processes once users go to a website. My question is very broad but for example I'd like to poll a JSON API every minute or so and send the user a web notification anytime the response from the JSON API changes. Is this possible with service workers? How can I accomplish this?

If this is possible, then is it possible that I can run a WebAssembly file in a service worker so that the application is running even when the website is not open?

Or can I run a service worker to grab the latest version of a site and have it cached so that the website loads immediately on their next visit?

1 Answers1

1

It's not possible to register a persistent background process that continues running indefinitely after a user visits a web site.

It is possible to register a service worker when visiting a web site. The service worker will not run most of the time, but can be "woken up" by an event like an incoming push notification, even if the user doesn't currently have a page open associated with your web app.

By design, when a service worker is woken up in that sort of fashion, it will only run for a short period of time before it's terminated. It is also expected to show a notification to the user letting them know that something is going on. Service workers that are woken up via push events but which do not show notifications might find themselves disabled by a browser.

Jeff Posnick
  • 53,580
  • 14
  • 141
  • 167