diff --git a/toys/facelight/sw.js b/toys/facelight/sw.js index e8cd01a..bb81c0e 100644 --- a/toys/facelight/sw.js +++ b/toys/facelight/sw.js @@ -1,10 +1,11 @@ // jshint asi:true -var cacheName = "v2"; +var cacheName = "v1"; var content = [ "index.html", "app.js", - "app.png", + "app.css", + "app.svg", ] @@ -12,12 +13,6 @@ self.addEventListener("install", preCache) self.addEventListener("fetch", cachingFetch) self.addEventListener("activate", handleActivate) -function handleActivate(event){ - event.waitUntil( - cleanup() - ) -} - async function cleanup(event) { let cacheNames = await caches.keys() for (let name of cacheNames) { @@ -28,6 +23,11 @@ async function cleanup(event) { } } +function handleActivate(event){ + event.waitUntil(cleanup()) +} + + function preCache(event) { event.waitUntil( caches.open(cacheName) @@ -37,14 +37,10 @@ function preCache(event) { // Go try to pull a newer version from the network, // but return what's in the cache for this request -function cachingFetch(event) { - fetch(event.request) - .then(resp => { - caches.open(cacheName) - .then(cache => { - cache.put(event.request, resp.clone()) - }) - }) +async function cachingFetch(event) { + let resp = await fetch(event.request) + let cache = await caches.open(cacheName) + cache.put(event.request, resp.clone()) event.respondWith(caches.match(event.request)) }