From b9d5983b17adbd238fdb8a41d926dacf53730675 Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Sun, 14 Nov 2021 17:53:31 +0100 Subject: Inline style sheet in EJS template to prevent FOUC. --- server.js | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'server.js') diff --git a/server.js b/server.js index 470eba9..a6c8394 100644 --- a/server.js +++ b/server.js @@ -87,7 +87,14 @@ io.use(passport_socket.authorize({ store: session_store, })); -app.use(express.static('public')); +const is_immutable = /\.(svg|png|jpg|jpeg|woff2)$/; + +function setHeaders(res, path) { + if (is_immutable.test(path)) + res.set("Cache-Control", "public, max-age=86400, immutable"); +} + +app.use(express.static('public', { setHeaders: setHeaders })); /* * MISC FUNCTIONS -- cgit v1.2.3