From b1ac2a507daa760edb201871d6055aa8ce7f0428 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Wed, 21 Feb 2024 10:06:11 +0700 Subject: [PATCH 1/2] set Cache-Control header in _document --- pages/_document.tsx | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/pages/_document.tsx b/pages/_document.tsx index 48244465..a7f2f558 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -64,6 +64,16 @@ class MyDocument extends Document { ): Promise { invariant(context.req) const jwt = context.req?.cookies?.[COOKIE_JWT_TOKEN] || null + + // set cache control header + context.res?.setHeader( + 'Cache-Control', + `${ + // make the cache private if user is logged in + jwt ? 'private' : 'public' + }, max-age=10, stale-while-revalidate=10`, + ) + const environment = await getEnvironment() // the `getClient` needs to be reset on every request as early as possible and before any rendering const apolloClient = getClient( From aad00023d07501dea8037aca878f5ce821cd5019 Mon Sep 17 00:00:00 2001 From: Nicolas Mahe Date: Wed, 21 Feb 2024 16:35:37 +0700 Subject: [PATCH 2/2] Update pages/_document.tsx --- pages/_document.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/_document.tsx b/pages/_document.tsx index a7f2f558..0de9001b 100644 --- a/pages/_document.tsx +++ b/pages/_document.tsx @@ -71,7 +71,7 @@ class MyDocument extends Document { `${ // make the cache private if user is logged in jwt ? 'private' : 'public' - }, max-age=10, stale-while-revalidate=10`, + }, max-age=10, stale-while-revalidate=50`, ) const environment = await getEnvironment()