Improved service worker
This commit is contained in:
parent
bb97c621e6
commit
82e37c52ac
@ -52,6 +52,7 @@ class MyCache {
|
|||||||
|
|
||||||
store(request: RequestInfo, response: Response) {
|
store(request: RequestInfo, response: Response) {
|
||||||
return caches.open(this.version).then(cache => {
|
return caches.open(this.version).then(cache => {
|
||||||
|
// This can fail if the disk space quota has been exceeded.
|
||||||
return cache.put(request, response)
|
return cache.put(request, response)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
@ -136,11 +137,14 @@ class MyServiceWorker {
|
|||||||
let clone = response.clone()
|
let clone = response.clone()
|
||||||
|
|
||||||
// Save the new version of the resource in the cache
|
// Save the new version of the resource in the cache
|
||||||
let cacheRefresh = this.cache.store(request, clone)
|
let cacheRefresh = this.cache.store(request, clone).catch(err => {
|
||||||
|
console.error(err)
|
||||||
|
// TODO: Tell client that the quota is exceeded (disk full).
|
||||||
|
})
|
||||||
|
|
||||||
CACHEREFRESH.set(request.url, cacheRefresh)
|
CACHEREFRESH.set(request.url, cacheRefresh)
|
||||||
|
|
||||||
if(request.url === "/styles") {
|
if(request.url.endsWith("/styles")) {
|
||||||
console.log("/styles fetched", response.headers.get("ETag"))
|
console.log("/styles fetched", response.headers.get("ETag"))
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -157,7 +161,7 @@ class MyServiceWorker {
|
|||||||
servedETag = response.headers.get("ETag")
|
servedETag = response.headers.get("ETag")
|
||||||
ETAGS.set(request.url, servedETag)
|
ETAGS.set(request.url, servedETag)
|
||||||
|
|
||||||
if(request.url === "/styles") {
|
if(request.url.endsWith("/styles")) {
|
||||||
console.log("/styles served", servedETag)
|
console.log("/styles served", servedETag)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user