Getting Started
For web developer documentation, see:
- Jake Archibald's "simple-serviceworker-tutorial"
- "Introduction to Service Worker" at html5rocks.com
- "The Offline Cookbook"
- "Is Service Worker Ready Yet?"
If you are a Chromium developer, read on!
Here's how to get a demo Service Worker up and running:
Steps:
- Open the demo at https://googlechrome.github.io/samples/service-worker/basic/index.html (source)
- Open the Inspector. Things are logged there later on.
- Try visiting Cleveland and get a 404. Go back.
- Click the 'Register' button, watch the Inspector console, then try visiting Cleveland again... oooh.
- 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
On a system with python:
$ 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:
- Configure your local server to serve your Service Worker script as non-cacheable (cache-control: no-cache)
- After you made changes to your service worker script:
- close all but one of the tabs pointing to your web application
- hit shift-reload to bypass the service worker as to ensure that the remaining tab isn't under the control of a service worker
- hit reload to let the newer version of the Service Worker control the page.
Documentation
- For an overview of the possibilities: Jake's ServiceWorker is coming, look busy talk (30min)