Disable client side page cache on some pages

This commit is contained in:
DrMint 2024-07-29 07:57:36 +02:00
parent 1c85884f70
commit e26ac32903
5 changed files with 12 additions and 4 deletions

View File

@ -13,11 +13,13 @@ export const addCommonHeadersMiddleware = defineMiddleware(async ({ url }, next)
response.headers.set("X-Robots-Tag", "none");
response.headers.set("Vary", "Cookie");
if (import.meta.env.CACHE_CONTROL !== "true") {
if (!response.headers.has("cache-control")) {
if (import.meta.env.CACHE_CONTROL !== "true" && !response.headers.has("cache-control")) {
response.headers.set("Cache-Control", "no-store");
} else {
response.headers.set("Cache-Control", "max-age=86400, stale-while-revalidate=86400");
}
}
return response;
});

View File

@ -3,6 +3,8 @@ import AppLayout from "components/AppLayout/AppLayout.astro";
import Button from "components/Button.astro";
import { getI18n } from "src/i18n/i18n";
Astro.response.headers.set("Cache-Control", "no-store");
const { t, getLocalizedUrl } = await getI18n(Astro.locals.currentLocale);
---

View File

@ -4,6 +4,8 @@ import Button from "components/Button.astro";
import Card from "components/Card.astro";
import { getI18n } from "src/i18n/i18n";
Astro.response.headers.set("Cache-Control", "no-store");
interface Props {
error: unknown;
}

View File

@ -1,3 +1,4 @@
---
Astro.response.headers.set("Cache-Control", "no-store");
return Astro.redirect("https://discord.com/invite/5mcXcRAczj");
---

View File

@ -19,6 +19,7 @@ import { Collections } from "src/shared/payload/constants";
import { meilisearch } from "src/services";
Astro.locals.pageCaching = false;
Astro.response.headers.set("Cache-Control", "no-store");
type State = {
q: string;