fix: separate jsHash for app.js cache busting

This commit is contained in:
M1 2026-03-18 09:43:11 +04:00
parent fa8ff8b361
commit 641af86779
2 changed files with 4 additions and 2 deletions

View File

@ -9,6 +9,8 @@ import { createHash } from "crypto";
// Generate a cache-buster hash from the CSS file content at startup // Generate a cache-buster hash from the CSS file content at startup
const cssFile = Bun.file(resolve(import.meta.dir, "../dashboard/tailwind.css")); 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 cssHash = createHash("md5").update(await cssFile.bytes()).digest("hex").slice(0, 8);
const jsFile = Bun.file(resolve(import.meta.dir, "../dashboard/app.js"));
const jsHash = createHash("md5").update(await jsFile.bytes()).digest("hex").slice(0, 8);
const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, defaultExtension: ".ejs" }); const eta = new Eta({ views: resolve(import.meta.dir, "../views"), cache: true, defaultExtension: ".ejs" });
@ -61,7 +63,7 @@ function escapeHtmlSSR(str: string): string {
} }
export function html(template: string, data: Record<string, unknown> = {}) { export function html(template: string, data: Record<string, unknown> = {}) {
return new Response(eta.render(template, { ...data, timeAgoSSR, sparklineSSR, latencyChartSSR, escapeHtmlSSR, cssHash }), { return new Response(eta.render(template, { ...data, timeAgoSSR, sparklineSSR, latencyChartSSR, escapeHtmlSSR, cssHash, jsHash }), {
headers: { "content-type": "text/html; charset=utf-8" }, headers: { "content-type": "text/html; charset=utf-8" },
}); });
} }

View File

@ -6,7 +6,7 @@
<title>PingQL<%= it.title ? ` — ${it.title}` : '' %></title> <title>PingQL<%= it.title ? ` — ${it.title}` : '' %></title>
<link rel="stylesheet" href="/dashboard/tailwind.css?v=<%= it.cssHash %>"> <link rel="stylesheet" href="/dashboard/tailwind.css?v=<%= it.cssHash %>">
<link rel="stylesheet" href="/dashboard/app.css?v=<%= it.cssHash %>"> <link rel="stylesheet" href="/dashboard/app.css?v=<%= it.cssHash %>">
<script src="/dashboard/app.js?v=<%= it.cssHash %>"></script> <script src="/dashboard/app.js?v=<%= it.jsHash %>"></script>
<% if (it.scripts) { it.scripts.forEach(function(s) { %> <% if (it.scripts) { it.scripts.forEach(function(s) { %>
<script src="<%= s %>"></script> <script src="<%= s %>"></script>
<% }) } %> <% }) } %>