feat: cache-bust static assets with CSS content hash on startup

This commit is contained in:
M1
2026-03-17 09:44:18 +04:00
parent 6342ec907f
commit 41bfe52f10
2 changed files with 9 additions and 4 deletions
+6 -1
View File
@@ -4,6 +4,11 @@ import { resolve } from "path";
import { resolveKey } from "./auth";
import sql from "../db";
import { sparkline } from "../utils/sparkline";
import { createHash } from "crypto";
// Generate a cache-buster hash from the CSS file content at startup
const cssFile = Bun.file(resolve(import.meta.dir, "../dashboard/tailwind.css"));
const cssHash = createHash("md5").update(await cssFile.bytes()).digest("hex").slice(0, 8);
const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, defaultExtension: ".ejs" });
@@ -56,7 +61,7 @@ function escapeHtmlSSR(str: string): string {
}
function html(template: string, data: Record<string, unknown> = {}) {
return new Response(eta.render(template, { ...data, timeAgoSSR, sparklineSSR, latencyChartSSR, escapeHtmlSSR }), {
return new Response(eta.render(template, { ...data, timeAgoSSR, sparklineSSR, latencyChartSSR, escapeHtmlSSR, cssHash }), {
headers: { "content-type": "text/html; charset=utf-8" },
});
}