mirror of
https://github.com/protomaps/PMTiles.git
synced 2026-02-04 10:51:07 +00:00
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:
15
js/index.ts
15
js/index.ts
@@ -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, {
|
||||
|
||||
Reference in New Issue
Block a user