Disabled cache refresh in service worker

This commit is contained in:
Eduard Urbach 2018-02-20 09:13:49 +01:00
parent f47fb93ddd
commit 93337d65c4

View File

@ -374,50 +374,50 @@ class MyClient {
// onDOMContentLoaded is called when the client sent this service worker // onDOMContentLoaded is called when the client sent this service worker
// a message that the page has been loaded. // a message that the page has been loaded.
onDOMContentLoaded(url: string) { onDOMContentLoaded(url: string) {
let refresh = serviceWorker.reloads.get(url) // let refresh = serviceWorker.reloads.get(url)
let servedETag = ETAGS.get(url) // let servedETag = ETAGS.get(url)
// If the user requests a sub-page we should prefetch the full page, too. // // If the user requests a sub-page we should prefetch the full page, too.
if(url.includes("/_/") && !url.includes("/_/search/")) { // if(url.includes("/_/") && !url.includes("/_/search/")) {
var prefetch = true // var prefetch = true
for(let pattern of EXCLUDECACHE.keys()) { // for(let pattern of EXCLUDECACHE.keys()) {
if(url.includes(pattern)) { // if(url.includes(pattern)) {
prefetch = false // prefetch = false
break // break
} // }
} // }
if(prefetch) { // if(prefetch) {
this.prefetchFullPage(url) // this.prefetchFullPage(url)
} // }
} // }
if(!refresh || !servedETag) { // if(!refresh || !servedETag) {
return Promise.resolve() // return Promise.resolve()
} // }
return refresh.then(async (response: Response) => { // return refresh.then(async (response: Response) => {
// When the actual network request was used by the client, response.bodyUsed is set. // // When the actual network request was used by the client, response.bodyUsed is set.
// In that case the client is already up to date and we don"t need to tell the client to do a refresh. // // In that case the client is already up to date and we don"t need to tell the client to do a refresh.
if(response.bodyUsed) { // if(response.bodyUsed) {
return // return
} // }
// Get the ETag of the cached response we sent to the client earlier. // // Get the ETag of the cached response we sent to the client earlier.
let eTag = response.headers.get("ETag") // let eTag = response.headers.get("ETag")
// Update ETag // // Update ETag
ETAGS.set(url, eTag) // ETAGS.set(url, eTag)
// If the ETag changed, we need to do a reload. // // If the ETag changed, we need to do a reload.
if(eTag !== servedETag) { // if(eTag !== servedETag) {
return this.reloadContent(url) // return this.reloadContent(url)
} // }
// Do nothing // // Do nothing
return Promise.resolve() // return Promise.resolve()
}) // })
} }
prefetchFullPage(url: string) { prefetchFullPage(url: string) {