
Setting up service workers
In order to get service workers running, we need to serve our code via Hyper Text Transfer Protocol Secure (HTTPS). Service workers are designed to run only across HTTPS for security reasons. Source code repositories such as GitHub support HTTPS, where you can host your files.
Getting ready
If you are using a newer version of a browser, the chances are that service workers are already enabled on it. But, if that is not the case, we will have to change few things in the browser settings. In the following section, we are going to cover how to enable service worker features in Chrome and Firefox.
How to do it...
Follow the steps below to enable service worker in Chrome and Firefox.
Chrome
To experiment in Chrome, you need to download Chrome Canary:
- Go to https://www.google.com/chrome/browser/canary.html and download the latest version.
- Open Chrome Canary and type
chrome://flags
. - Turn on
experimental-web-platform-features
. - Restart the browser.
- The following image shows experimental features on the Chrome browser, where you enable the Experimental Web Platform feature by clicking on the Enable link underneath:
Firefox
To experiment in Firefox, you need to download Firefox Nightly:
- Go to https://nightly.mozilla.org/ and download the latest version.
- Open Firefox Nightly, and go to
about:config
. - Set
experimental-web-platform-features
totrue
. - Restart the browser.
Note
At the time of writing, Opera offers partial support for service workers, including basic support, as well as installing and uninstalling events. Internet Explorer and Safari do not support service workers.
Service workers are currently an experimental technology, meaning the syntax and the behavior are subject to change in future versions as the specification changes.