— Keep learning, keep building and keep growing

A Service worker is basically a script (js file) that runs in your background and assists in offline-first web application development. which will opens the door to features that don’t need a web page or user interaction.

List of advantages :

Image for post

Service worker Key Points

  1. Rich offline experiences
  2. Push notifications
  3. Periodic background syncs: Periodic Background Sync enables web applications to periodically synchronize data in the background, bringing web apps closer to the behaviour of a native app.

Note:

  • You’re using Chrome 80 or later.
  • You install the web app before enabling periodic background sync.

Before service worker, there was one other API that gave users an offline experience on the web called AppCache. There are a number of issues with the AppCache API that service workers were designed to avoid.

Insights about Service workers

A service worker is a programmable network proxy, allowing you to control how network requests from your page are handled.

It’s terminated when not in use and restarted when it’s next needed, If there is information that you need to persist and reuse across restarts, service workers do have access to the IndexedDB API.

Service worker extensively uses “Promises”. Don’t miss it. Read, understand, get command on this to get a clear picture of service workers.

The reason this is such an exciting API is that it allows you to support offline experiences, giving developers complete control over the experience.

Service workers are terminated when not in use and restored when required. It acts as a programmable network proxy, allowing developers to handle how network requests from the web page are handled. So the developers can take appropriate action based on the availability of the network.

Keep in mind that service workers need to be served over HTTPS, otherwise, the browser won’t register them.

Browser Support

The first browser to implement service worker support was Chrome 80 or later, but Opera, Firefox support service workers. Microsoft Edge is currently working on their implementations.

  • Chrome Canary: Go to chrome://flags and turn on experimental-web-platform-features; restart the browser (note that some features are now enabled by default in Chrome.)
  • Firefox Nightly: Go to about:config and set dom.serviceWorkers.enabled too true; restart the browser.
  • Opera: Go to opera://flags and enable Support for ServiceWorker; restart the browser.
  • Microsoft Edge: Go to about:flags and tick Enable service workers; restart the browser.

Can I use_ Thanks to Jake Archibald’s — For a great clarity on each browser with versions support._

#service-worker #js #pwa-development #javascript #react #programming

What are Service workers?
1.20 GEEK