To install a service worker you need to kick-start the process by registering it on your page. This tells the browser where your service worker JavaScript file lives.

every time a page loads without concern; the browser will figure out if the service worker is already registered or not and handle it accordingly.

You can call below

This code checks to see if the service worker API is available, and if it is, the service worker at /

sw.js

is registered once the page is loaded.