--- feature_name: Basic Service Worker chrome_version: 40 feature_id: 6561526227927040 local_css_files: ['styles.css'] ---
This sample demonstrates a basic service worker that could be used as-is, or as a starting point for further customization.
You can confirm the service worker's behavior using the Application panel of Chrome's DevTools.
CACHES.PRECACHE
name to pick up
new versions after updating anything!
cache.addAll()
call may be fulfilled with responses from
the HTTP cache, depending on the HTTP caching headers you use. If you
are using
HTTP caching
and unversioned resources, it can be safer to
cache-bust
your precaching requests.
sw-toolbox
which provides
cache-expiration
is recommended.
The following demo illustrates the service worker's runtime caching by loading images in response to clicking the button below.
The first time a given image is requested, the service worker will be load it from the network, but each subsequent time, it will be retrieved from the cache.
{% include js_snippet.html filename='demo.js' %} {% include js_snippet.html filename='service-worker.js' displayonly=true title="Service Worker's JavaScript" %}