service worker

From IndieWeb


service workers are scripts that run in the background, separate from tabs with the site open, and are commonly used for offline functionality and push notifications.

Why

Why would you want to add a service worker to your site? Many reasons, though most commonly:

  • offline support — allow visitors to still browse (parts of) your site when not connected. Ideally start with offline first support. See offline#Why for more reasons.
  • local support — allow visitors (including yourself!) to interact with your site locally, independent of any network connection (thus not blocked / slowed by) and then sync those interactions in the background.

For a broader introduction including more reasons why, see:

How to

This section is a stub, please expand it with articles that have helped you get started!

How to get started with a service worker:

To support more features with your service worker, see the "How to" sections for those features! E.g.

Indieweb Examples

Jeremy Keith

Jeremy Keith on adactio.com since 2015-11-07:

Tantek

Tantek Çelik on tantek.com since 2019-10-20:

... add yourself

  • add yourself here

Brainstorming

Things to maybe try doing with service workers.

See the Brainstorming sections of features supported by service workers! E.g.

Drawbacks

Your mileage may vary possibly depending on one's approach to caching. Consider this article from Google as an example of the potential complexity of strategies available: https://web.dev/articles/service-worker-caching-and-http-caching. It is not a simple plug and play experience for every website.

Morgan briefly began to use an offline-capable service worker script for single page sites but found difficulty in cache busting when desired at the specific times during development or rapid updates. More or less, Morgan found he did not fully understand how the service worker lifecycle worked, and after this experience, he opted to remove the service worker script from his personal sites until a future date. There are ways to mitigate these issues but it was not trivial to his mind.

See Also