fix(cache): reduce CSS/JS cache from 1 year to 1 hour

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 <noreply@anthropic.com>
This commit is contained in:
TheFlow 2025-10-24 18:49:44 +13:00
parent c01b08ef1b
commit 97d345357d

View file

@ -101,9 +101,10 @@ app.use((req, res, next) => {
res.setHeader('Pragma', 'no-cache'); res.setHeader('Pragma', 'no-cache');
res.setHeader('Expires', '0'); 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')) { 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 // Images and fonts: Long cache
else if (path.match(/\.(jpg|jpeg|png|gif|svg|ico|woff|woff2|ttf|eot)$/)) { else if (path.match(/\.(jpg|jpeg|png|gif|svg|ico|woff|woff2|ttf|eot)$/)) {