Fix double request
This commit is contained in:
parent
6b64cc62dd
commit
1f3507ea9e
@ -232,7 +232,7 @@ export class AnimeNotifier {
|
||||
if(message.url.includes("/_/")) {
|
||||
// Content reload
|
||||
this.contentLoadedActions.then(() => {
|
||||
this.reloadContent()
|
||||
this.reloadContent(true)
|
||||
})
|
||||
} else {
|
||||
// Full page reload
|
||||
@ -318,11 +318,16 @@ export class AnimeNotifier {
|
||||
}
|
||||
}
|
||||
|
||||
reloadContent() {
|
||||
reloadContent(cached?: boolean) {
|
||||
console.log("reload content", "/_" + this.app.currentPath)
|
||||
|
||||
let headers = new Headers()
|
||||
|
||||
if(!cached) {
|
||||
headers.append("X-Reload", "true")
|
||||
} else {
|
||||
headers.append("X-CacheOnly", "true")
|
||||
}
|
||||
|
||||
let path = this.app.currentPath
|
||||
this.lastReloadContentPath = path
|
||||
|
@ -137,10 +137,17 @@ self.addEventListener("fetch", async (evt: FetchEvent) => {
|
||||
return evt.waitUntil(evt.respondWith(fetch(request)))
|
||||
}
|
||||
|
||||
// Forced cache response?
|
||||
if(request.headers.get("X-CacheOnly") === "true") {
|
||||
console.log("forced cache response")
|
||||
return evt.waitUntil(fromCache(request))
|
||||
}
|
||||
|
||||
let servedETag = undefined
|
||||
|
||||
// Start fetching the request
|
||||
let refresh = fetch(request).then(response => {
|
||||
console.log(response)
|
||||
let clone = response.clone()
|
||||
|
||||
// Save the new version of the resource in the cache
|
||||
@ -158,11 +165,11 @@ self.addEventListener("fetch", async (evt: FetchEvent) => {
|
||||
|
||||
// Forced reload
|
||||
if(request.headers.get("X-Reload") === "true") {
|
||||
return evt.waitUntil(refresh.then(response => {
|
||||
return evt.waitUntil(evt.respondWith(refresh.then(response => {
|
||||
servedETag = response.headers.get("ETag")
|
||||
ETAGS.set(request.url, servedETag)
|
||||
return response
|
||||
}))
|
||||
})))
|
||||
}
|
||||
|
||||
// Try to serve cache first and fall back to network response
|
||||
|
Loading…
Reference in New Issue
Block a user