mirror of
https://github.com/LemmyNet/lemmy-ui.git
synced 2024-11-01 01:59:56 +00:00
change max-age to 5 for non-authed responses
This commit is contained in:
parent
339cefa2b0
commit
d8ee0ec78a
1 changed files with 4 additions and 2 deletions
|
@ -18,7 +18,7 @@ export function setDefaultCsp({
|
||||||
|
|
||||||
// Set cache-control headers. If user is logged in, set `private` to prevent storing data in
|
// 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
|
// 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).
|
// 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
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||||
|
@ -29,6 +29,7 @@ export function setCacheControl(
|
||||||
) {
|
) {
|
||||||
const user = UserService.Instance;
|
const user = UserService.Instance;
|
||||||
let caching: string;
|
let caching: string;
|
||||||
|
|
||||||
if (
|
if (
|
||||||
req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) ||
|
req.path.match(/\.(js|css|txt|manifest\.webmanifest)\/?$/) ||
|
||||||
req.path.includes("/css/themelist")
|
req.path.includes("/css/themelist")
|
||||||
|
@ -39,9 +40,10 @@ export function setCacheControl(
|
||||||
if (user.auth()) {
|
if (user.auth()) {
|
||||||
caching = "private";
|
caching = "private";
|
||||||
} else {
|
} else {
|
||||||
caching = "public, max-age=60";
|
caching = "public, max-age=5";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
res.setHeader("Cache-Control", caching);
|
res.setHeader("Cache-Control", caching);
|
||||||
|
|
||||||
next();
|
next();
|
||||||
|
|
Loading…
Reference in a new issue