Service Worker Update

Background: Service Worker?

<!DOCTYPE html>
<html>
  <head>
    <script>
      navigator.registerServiceWorker("/*", "sw.js", "...");
    </script>
  </head>
</html>
// http://example.com/sw.js
this.version = 1;

importScripts("http://cdn.thirdparty.com/utility.js")

this.addEventListener("install", function(e) {
  var cats = new Cache(/* ...urls */);
  // cache versioning is still ugly
  this.caches.set("v1 cat images", cats);
  e.waitUntil(cats.ready());
});

this.addEventListener("fetch", function(e) {
  if (e.request.url.toString() == "http://example.com/data.json") {
    e.respondWith(new SameOriginResponse({
      statusCode: 200,
      body: JSON.stringify({
        cats: [ /* ... */ ]
      })
    }));
  }
});

Service Worker Update

Challenges