Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,16 @@ class MyDocument extends Document {
): Promise<DocumentInitialProps & MyDocumentProps> {
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=50`,
)

const environment = await getEnvironment()
// the `getClient` needs to be reset on every request as early as possible and before any rendering
const apolloClient = getClient(
Expand Down