Add cache busting to asset urls to bust assets with bad headers

This commit is contained in:
evanpelle
2026-05-02 07:26:06 -06:00
parent 4d5b7c0fb6
commit d071c8228f
+13 -2
View File
@@ -33,6 +33,9 @@ const ROOT_PUBLIC_FILES = new Set([
const manifestCache = new Map<string, AssetManifest>();
// Bump this to force-invalidate all CDN-cached assets (e.g. after a bad deploy with wrong cache headers).
const CACHE_BUST_VERSION = "2";
type DerivedPublicAssetRenderContext = {
resourcesDir: string;
relativePath: string;
@@ -50,11 +53,19 @@ function toPosixPath(filePath: string): string {
function createContentHash(filePath: string): string {
const content = fs.readFileSync(filePath);
return createHash("sha256").update(content).digest("hex").slice(0, 12);
return createHash("sha256")
.update(CACHE_BUST_VERSION)
.update(content)
.digest("hex")
.slice(0, 12);
}
function createStringHash(content: string): string {
return createHash("sha256").update(content).digest("hex").slice(0, 12);
return createHash("sha256")
.update(CACHE_BUST_VERSION)
.update(content)
.digest("hex")
.slice(0, 12);
}
function createHashedAssetUrl(relativePath: string, hash: string): string {