[object Object]

← back to Robet Site

round2 item (3): differentiated static caching — images max-age=86400, html/css/js no-cache + ETag (304 revalidation), updates stay instant without fingerprinting

65be242c85c99bcaa33244ee0935ac762b692b22 · 2026-06-29 23:02:53 -0700 · Steve

Files touched

Diff

commit 65be242c85c99bcaa33244ee0935ac762b692b22
Author: Steve <steve@designerwallcoverings.com>
Date:   Mon Jun 29 23:02:53 2026 -0700

    round2 item (3): differentiated static caching — images max-age=86400, html/css/js no-cache + ETag (304 revalidation), updates stay instant without fingerprinting
---
 server.js | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/server.js b/server.js
index cabd5d4..dd52d82 100644
--- a/server.js
+++ b/server.js
@@ -139,7 +139,19 @@ app.delete('/api/keys/:name', adminAuth, (req, res) => {
 
 app.get('/admin', adminAuth, (_req, res) => res.sendFile(path.join(__dirname, 'public', 'admin.html')));
 
-app.use(express.static(path.join(__dirname, 'public')));
+// Differentiated caching: stable images get a real maxAge; HTML/CSS/JS revalidate
+// (no fingerprinting → ETag/304 keeps revalidation cheap while updates stay instant).
+app.use(express.static(path.join(__dirname, 'public'), {
+  etag: true,
+  lastModified: true,
+  setHeaders(res, filePath) {
+    if (/\.(png|jpe?g|gif|webp|svg|ico)$/i.test(filePath)) {
+      res.setHeader('Cache-Control', 'public, max-age=86400');     // images: 1 day
+    } else {
+      res.setHeader('Cache-Control', 'no-cache');                   // html/css/js: revalidate
+    }
+  },
+}));
 
 // ── custom 404 (after static) ──
 app.use((req, res) => {

← c54f681 loop ledger: round2 item (5) done + deployed  ·  back to Robet Site  ·  loop ledger: round2 item (3) done + deployed de5f5ab →