Chrome windows cache workaround (#454)

js 3.1.0

* Disable browser caching on chrome on windows [#442]
* work around for chromium issue: https://issues.chromium.org/issues/40542704
This commit is contained in:
Brandon Liu
2024-09-19 23:26:09 +08:00
committed by GitHub
parent 897d6f186e
commit ce959e50b0
7 changed files with 42 additions and 7 deletions

View File

@@ -359,11 +359,24 @@ export class FetchSource implements Source {
customHeaders: Headers;
/** @hidden */
mustReload: boolean;
/** @hidden */
chromeWindowsNoCache: boolean;
constructor(url: string, customHeaders: Headers = new Headers()) {
this.url = url;
this.customHeaders = customHeaders;
this.mustReload = false;
let userAgent = "";
if ("navigator" in globalThis) {
//biome-ignore lint: cf workers
userAgent = (globalThis as any).navigator.userAgent || "";
}
const isWindows = userAgent.indexOf("Windows") > -1;
const isChromiumBased = /Chrome|Chromium|Edg|OPR|Brave/.test(userAgent);
this.chromeWindowsNoCache = false;
if (isWindows && isChromiumBased) {
this.chromeWindowsNoCache = true;
}
}
getKey() {
@@ -404,6 +417,8 @@ export class FetchSource implements Source {
let cache: string | undefined;
if (this.mustReload) {
cache = "reload";
} else if (this.chromeWindowsNoCache) {
cache = "no-store";
}
let resp = await fetch(this.url, {