Fixed + cleaned service worker
This commit is contained in:
parent
e9c4f78d98
commit
c669e6f812
|
@ -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 => {
|
||||
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))
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue