Blink‎ > ‎ServiceWorker‎ > ‎

Getting Started

Here's how to get a demo Service Worker up and running:

Steps:

  1. Install Chrome Canary (Linux users can build Chromium, Android users can build ChromeShell.)
  2. Open the browser and enable the Experimental Web Platform Features flag by cutting and pasting this URL: chrome://flags/#enable-experimental-web-platform-features . Enable the Experimental Web Platform Features option, then restart the browser.
  3. Open the demo at https://googlechrome.github.io/samples/service-worker/basic/index.html  (source
  4. Open the Inspector. Things are logged there later on.
  5. Try visiting Cleveland and get a 404. Go back.
  6. Click the 'Register' button, watch the Inspector console, then try visiting Cleveland again... oooh.
  7. Go to chrome://inspect#service-workers and click on Inspect to open the Inspector and debug your Service Worker.

Running it locally

  • Clone the git repo 
  • Navigate to the samples/service-worker/basic folder
  • Start a local webserver (see below)
  • Open http://localhost:8080/index.html (or whatever path and port you set up.) 
  • Feel free to edit the JS and try some new things!

How to run a local server

This is hard if you have never done it before. Ask a buddy or search!

On Linux, try: twistd -n web --path . --port 8080

On Windows or OS X, try: python -m SimpleHTTPServer 8080

On Android use Chrome Developer Tools' port forwarding.

Development flow

In order to guarantee that the latest version of your Service Worker script is being used, follow these instructions:
  1. Configure your local server to serve your Service Worker script as non-cacheable (cache-control: no-cache)
  2. After you made changes to your service worker script:
    1. close all but one of the tabs pointing to your web application
    2. hit shift-reload to bypass the service worker as to ensure that the remaining tab isn't under the control of a service worker
    3. hit reload to let the newer version of the Service Worker control the page.


Documentation


Comments