From f4a23ae80566104efaea80e8939b38333c014c68 Mon Sep 17 00:00:00 2001 From: sravan Date: Wed, 24 Jun 2026 16:30:17 +0530 Subject: [PATCH] fix(cache): serve HTML with no-store so deploys reach browsers without a hard refresh Browsers were serving a cached old home.html on normal reloads (only incognito/ hard-refresh got the new one). HTML now sends Cache-Control: no-store; versioned assets keep ETag revalidation. Bumps build marker to push4. Co-Authored-By: Claude Opus 4.8 --- server/public/home.html | 2 +- server/static.js | 13 ++++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/server/public/home.html b/server/public/home.html index 990bf4a..0ce3820 100644 --- a/server/public/home.html +++ b/server/public/home.html @@ -589,7 +589,7 @@ - +
Loading…
diff --git a/server/static.js b/server/static.js index b2954f2..633d56f 100644 --- a/server/static.js +++ b/server/static.js @@ -23,15 +23,22 @@ function serveStatic(req, res) { // tiny 304 (no re-download) when nothing changed — fast reloads, but always fresh on edits. fs.stat(fp, (serr, st) => { if (serr || !st.isFile()) return json(res, 404, { error: 'not found' }); - const ct = MIME[path.extname(fp)] || 'application/octet-stream'; + const ext = path.extname(fp); + const ct = MIME[ext] || 'application/octet-stream'; + // HTML entry pages are NEVER cached (no-store) so a deploy reaches every browser on the + // next load — no hard-refresh needed. Versioned assets (e.g. icons.js?v=) still revalidate + // cheaply via ETag/304. + const isHtml = ext === '.html'; const etag = '"' + st.size.toString(16) + '-' + Math.round(st.mtimeMs).toString(16) + '"'; - if (req.headers['if-none-match'] === etag) { + if (!isHtml && req.headers['if-none-match'] === etag) { res.writeHead(304, { ETag: etag, 'Cache-Control': 'no-cache' }); return res.end(); } fs.readFile(fp, (err, data) => { if (err) return json(res, 404, { error: 'not found' }); - res.writeHead(200, { 'Content-Type': ct, 'Cache-Control': 'no-cache', ETag: etag, 'Content-Length': st.size }); + const headers = { 'Content-Type': ct, 'Content-Length': st.size, 'Cache-Control': isHtml ? 'no-store, must-revalidate' : 'no-cache' }; + if (!isHtml) headers.ETag = etag; + res.writeHead(200, headers); res.end(data); }); });