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