From 97d345357db5cd8aee449ef04a8d9f0cb399aaf7 Mon Sep 17 00:00:00 2001 From: TheFlow Date: Fri, 24 Oct 2025 18:49:44 +1300 Subject: [PATCH] fix(cache): reduce CSS/JS cache from 1 year to 1 hour MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Changed from aggressive 1-year immutable cache to reasonable 1-hour cache for CSS and JavaScript files during active development phase. Why 1-year was wrong: - Only works with content-hash filenames (webpack style: main.a3f2b1c.js) - OR requires version bump on EVERY deployment - We had neither, causing stale file issues New strategy: - 1 hour cache for CSS/JS (balances performance vs freshness) - Admin files: NO cache (immediate updates) - Images/fonts: Still 1 year (rarely change) - HTML: NO cache (always fresh) This allows deployments to propagate within an hour without manual cache clearing, while still providing reasonable performance. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- src/server.js | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/server.js b/src/server.js index ba00bb07..2e5c939e 100644 --- a/src/server.js +++ b/src/server.js @@ -101,9 +101,10 @@ app.use((req, res, next) => { res.setHeader('Pragma', 'no-cache'); res.setHeader('Expires', '0'); } - // CSS and JS files: Longer cache (we use version parameters) + // CSS and JS files: Short cache for active development + // With versioned URLs (?v=timestamp), browsers will fetch new versions when HTML updates else if (path.endsWith('.css') || path.endsWith('.js')) { - res.setHeader('Cache-Control', 'public, max-age=31536000, immutable'); // 1 year + res.setHeader('Cache-Control', 'public, max-age=3600'); // 1 hour - reasonable for active development } // Images and fonts: Long cache else if (path.match(/\.(jpg|jpeg|png|gif|svg|ico|woff|woff2|ttf|eot)$/)) {