July 2018
Intermediate to advanced
354 pages
8h 51m
English
Service workers must be registered from a web page. This is done in a normal UI script. Before you call the register method, you should feature detect service worker support. If supported, the navigator object has a serviceWorker property:
if ('serviceWorker' in navigator) { }
If the browser supports service workers, you can then safely register your service worker. The serviceWorker object has a register method, so you need to supply a URL reference to the service worker script:
if ('serviceWorker' in navigator) { navigator.serviceWorker.register('/sw.js') .then(function(registration) { // Registration was successful }); }
The serviceWorker.register("sw path"[, options]) function accepts two parameters. The ...
Read now
Unlock full access