From the course: JavaScript: Progressive Web Applications

Unlock the full course today

Join today to access over 22,700 courses taught by industry experts or purchase this course individually.

Registering a service worker

Registering a service worker - JavaScript Tutorial

From the course: JavaScript: Progressive Web Applications

Start my 1-month free trial

Registering a service worker

- [Instructor] Open up main.js. If it's not visible on one of the tabs, you can double-click on it by expanding the js node in the Site Root. Let's begin by adding a simple conditional statement that checks for the existence of the serviceWorker object. So, beneath the toggleNav function, we're gonna ask whether or not the serviceWorker object actually exists. So, that conditional would read, if, and then refer to the serviceWorker object in navigator. And essentially, this just checks whether or not the serviceWorker object exists in the navigator object. Okay, I'm gonna set up an else clause because if we get here, then service workers are not supported and we'll just make note of that fact. So, I'll write out console.log and then a simple message. So how about Service Workers Not Supported. Okay, so to actually register the service worker we actually call the register method on the serviceWorker object. So, jump back into the if block and then I'll write a little comment here and…

Contents