Skip to content

Commit f9ff87a

Browse files
gitcommit90claude
andcommitted
site: content-hash version query on story/manual asset URLs
CDN edges cache /assets/ files for seven days, so a deploy that changes story.css or story.js kept serving the stale copy. Static pages now reference those assets with a ?v=<content hash> computed at boot, busting the cache exactly when contents change. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent a606ca5 commit f9ff87a

1 file changed

Lines changed: 7 additions & 1 deletion

File tree

site/server.mjs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,13 @@ const PRODUCT_PUBLIC = join(ROOT, "public");
1111
const pkg = JSON.parse(readFileSync(join(ROOT, "package.json"), "utf8"));
1212
const STORY_HTML = readFileSync(join(import.meta.dirname, "story.html"), "utf8");
1313
const MANUAL_HTML = readFileSync(join(import.meta.dirname, "manual.html"), "utf8");
14-
const STATIC_PAGES = { "/": STORY_HTML, "/manual": MANUAL_HTML, "/terms": readFileSync(join(import.meta.dirname, "terms.html"), "utf8"), "/privacy": readFileSync(join(import.meta.dirname, "privacy.html"), "utf8") };
14+
const ASSET_VERSION = createHash("sha256")
15+
.update(readFileSync(join(import.meta.dirname, "public/assets/story.css")))
16+
.update(readFileSync(join(import.meta.dirname, "public/assets/story.js")))
17+
.update(readFileSync(join(import.meta.dirname, "public/assets/manual.css")))
18+
.digest("hex").slice(0, 10);
19+
const versionAssets = (html) => html.replace(/\/assets\/(story|manual)\.(css|js)/g, (m) => `${m}?v=${ASSET_VERSION}`);
20+
const STATIC_PAGES = { "/": versionAssets(STORY_HTML), "/manual": versionAssets(MANUAL_HTML), "/terms": versionAssets(readFileSync(join(import.meta.dirname, "terms.html"), "utf8")), "/privacy": versionAssets(readFileSync(join(import.meta.dirname, "privacy.html"), "utf8")) };
1521
const VERSION = String(pkg.version || "");
1622
const HOST = process.env.SITE_HOST || "127.0.0.1";
1723
const PORT = Number(process.env.SITE_PORT || process.env.PORT || 8130);

0 commit comments

Comments
 (0)