[object Object]

← back to AsSeenInMovies

sitemap.xml: preserve Last-Modified+Cache-Control on cache-hit fast path + smoke

32e313c237aee6e16e13a227a35d5046fa7271fa · 2026-05-13 11:14:33 -0700 · SteveStudio2

Files touched

Diff

commit 32e313c237aee6e16e13a227a35d5046fa7271fa
Author: SteveStudio2 <stevestudio2@SteveStacStudio.lan>
Date:   Wed May 13 11:14:33 2026 -0700

    sitemap.xml: preserve Last-Modified+Cache-Control on cache-hit fast path + smoke
---
 server.js     | 5 +++++
 test/smoke.js | 2 ++
 2 files changed, 7 insertions(+)

diff --git a/server.js b/server.js
index 158bd5d..80a3686 100644
--- a/server.js
+++ b/server.js
@@ -1940,6 +1940,11 @@ const SITEMAP_TTL_MS = 10 * 60 * 1000;
 app.get('/sitemap.xml', async (_req, res) => {
   const now = Date.now();
   if (_sitemapCache.xml && (now - _sitemapCache.at) < SITEMAP_TTL_MS) {
+    // Cache hit — preserve the same headers as the cache-miss path so caches
+    // and CDNs see consistent Last-Modified / Cache-Control regardless of
+    // whether this request happened to warm the cache.
+    res.setHeader('Cache-Control', 'public, max-age=21600, stale-while-revalidate=86400');
+    res.setHeader('Last-Modified', new Date(_sitemapCache.at).toUTCString());
     return res.type('application/xml').send(_sitemapCache.xml);
   }
   try {
diff --git a/test/smoke.js b/test/smoke.js
index 8e975c9..ebf45ab 100644
--- a/test/smoke.js
+++ b/test/smoke.js
@@ -172,9 +172,11 @@ function check(name, cond, hint = '') {
   check('sitemap: 200',        r.status === 200);
   check('sitemap: urlset',     /<urlset/.test(r.body));
   check('sitemap: has /about', /<loc>[^<]*\/about<\/loc>/.test(r.body));
+  check('sitemap: Last-Modified', /GMT$/.test(r.headers['last-modified'] || ''));
   r = await fetch('/sitemap.txt');
   check('sitemap.txt: 200',    r.status === 200);
   check('sitemap.txt: has http URL', /^https?:\/\//.test(r.body));
+  check('sitemap.txt: Last-Modified', /GMT$/.test(r.headers['last-modified'] || ''));
   r = await fetch('/robots.txt');
   check('robots: 200',         r.status === 200);
   check('robots: disallow queue', /\/spotted\/queue/.test(r.body));

← a7da201 smoke: home perf budget <1500ms (cold-cache ceiling; regress  ·  back to AsSeenInMovies  ·  smoke: cover /healthz (200, ok JSON, no-store, HEAD method) 888e73e →