From 0a8a73c47d8fe0c63425af3ab0394ae52b0f3532 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 28 Dec 2021 16:29:37 +0100 Subject: Only set cache-control max-age on images and web fonts. --- server.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'server.js') diff --git a/server.js b/server.js index 8d4c24b..50fa751 100644 --- a/server.js +++ b/server.js @@ -79,12 +79,19 @@ function login_delete(res, sid) { * Web server setup. */ +function set_static_headers(res, path) { + if (path.match(/\.(jpg|png|svg|webp|ico|woff2)/)) + res.setHeader('Cache-Control', 'max-age=86400'); + else + res.setHeader('Cache-Control', 'max-age=0'); +} + let app = express(); app.set('x-powered-by', false); app.set('etag', false); app.set('view engine', 'pug'); app.use(compression()); -app.use(express.static('public', { etag: false, maxAge: 24*3600*1000 })); +app.use(express.static('public', { etag: false, cacheControl: false, setHeaders: set_static_headers })); app.use(express.urlencoded({extended:false})); let http_port = process.env.HTTP_PORT || 8080; -- cgit v1.2.3