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.
Service worker Key Points
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.
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.
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://flags
and turn on experimental-web-platform-features
; restart the browser (note that some features are now enabled by default in Chrome.)about:config
and set dom.serviceWorkers.enabled
too true; restart the browser.opera://flags
and enable Support for ServiceWorker
; restart the browser.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