From 19b0c855a9c95e98215da5bb7eec169155f00c1b Mon Sep 17 00:00:00 2001 From: dev Date: Sat, 12 Sep 2026 00:47:18 +0300 Subject: [PATCH] Cache HTML/JS/CSS with no-cache revalidation (ETag 304): browsers always get fresh pages after docker restart; vendor and image caches unchanged --- server.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/server.js b/server.js index 2f0019b..d0075b6 100644 --- a/server.js +++ b/server.js @@ -216,9 +216,17 @@ app.get('/uploads/thumb/:name', fileLimiter, async (req, res) => { return sendImageThumb(res, fp); }); +app.use((req, res, next) => { + const p = req.path; + if (!p.startsWith('/uploads') && !p.startsWith('/vendor')) { + res.setHeader('Cache-Control', 'no-cache'); + } + next(); +}); + app.use('/uploads', express.static(path.join(__dirname, 'uploads'), { maxAge: '365d', immutable: true })); app.use('/vendor', express.static(path.join(__dirname, 'public', 'vendor'), { maxAge: '30d' })); -app.use(express.static(path.join(__dirname, 'public'), { maxAge: '1h' })); +app.use(express.static(path.join(__dirname, 'public'))); const SESSION_TTL_MS = 30 * 24 * 60 * 60 * 1000;