From d8ee0ec78aed4c40b921d2b863db6afb7630587f Mon Sep 17 00:00:00 2001 From: Alec Armbruster <35377827+alectrocute@users.noreply.github.com> Date: Thu, 29 Jun 2023 13:33:30 -0400 Subject: [PATCH] change max-age to 5 for non-authed responses --- src/server/middleware.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/server/middleware.ts b/src/server/middleware.ts index 753fce9..84c568d 100644 --- a/src/server/middleware.ts +++ b/src/server/middleware.ts @@ -18,7 +18,7 @@ export function setDefaultCsp({ // Set cache-control headers. If user is logged in, set `private` to prevent storing data in // shared caches (eg nginx) and leaking of private data. If user is not logged in, allow caching -// all responses for 60 seconds to reduce load on backend and database. The specific cache +// all responses for 5 seconds to reduce load on backend and database. The specific cache // interval is rather arbitrary and could be set higher (less server load) or lower (fresher data). // // https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control @@ -29,6 +29,7 @@ export function setCacheControl( ) { const user = UserService.Instance; let caching: string; + if ( req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) || req.path.includes("/css/themelist") @@ -39,9 +40,10 @@ export function setCacheControl( if (user.auth()) { caching = "private"; } else { - caching = "public, max-age=60"; + caching = "public, max-age=5"; } } + res.setHeader("Cache-Control", caching); next(); -- 2.44.1