From 004de918ca27606261b84f882db4c198b6ebb3ec Mon Sep 17 00:00:00 2001 From: Antonio Young <81043669+Gomurmamma@users.noreply.github.com> Date: Tue, 15 Mar 2022 12:34:37 -0400 Subject: [PATCH 1/4] Update docs about Cache-Control default headers. --- docs/going-to-production.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/going-to-production.md b/docs/going-to-production.md index f65f055d0677..bf9f74b57b30 100644 --- a/docs/going-to-production.md +++ b/docs/going-to-production.md @@ -68,6 +68,11 @@ export async function getServerSideProps({ req, res }) { } } ``` +By default, `Cache-Control` headers will be set differently depending on how your page fetches data. + +If the page is using `getServerSideProps` or `getInitialProps`, then it will use the default `Cache-Control` header configured by `next start` in order to prevent accidental caching of responses that cannot be cached. + +If the page is using `getStaticProps` or automatic static optimization, then it will have s-maxage=REVALIDATE_SECONDS, stale-while-revalidate or if revalidate is not used s-maxage=31536000, stale-while-revalidate. > **Note:** Your deployment provider must support edge caching for dynamic responses. If you are self-hosting, you will need to add this logic to the edge yourself using a key/value store. If you are using Vercel, [edge caching works without configuration](https://vercel.com/docs/edge-network/caching). From 5189e8a685790db6374724f69e01528e59b872b9 Mon Sep 17 00:00:00 2001 From: Antonio Young <81043669+Gomurmamma@users.noreply.github.com> Date: Tue, 15 Mar 2022 14:52:29 -0400 Subject: [PATCH 2/4] Update docs: Override the default in case of gSSP --- docs/going-to-production.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/docs/going-to-production.md b/docs/going-to-production.md index bf9f74b57b30..77e35b072543 100644 --- a/docs/going-to-production.md +++ b/docs/going-to-production.md @@ -74,6 +74,8 @@ If the page is using `getServerSideProps` or `getInitialProps`, then it will use If the page is using `getStaticProps` or automatic static optimization, then it will have s-maxage=REVALIDATE_SECONDS, stale-while-revalidate or if revalidate is not used s-maxage=31536000, stale-while-revalidate. +If you want a different Cache-Control while using SSR you can use res.setHeader('Cache-Control', 'value_you_prefer'). + > **Note:** Your deployment provider must support edge caching for dynamic responses. If you are self-hosting, you will need to add this logic to the edge yourself using a key/value store. If you are using Vercel, [edge caching works without configuration](https://vercel.com/docs/edge-network/caching). ## Reducing JavaScript Size From 70ac82ef481aa4f1c7f20c821e0f46ea1ba229f8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Wed, 16 Mar 2022 11:39:57 +0100 Subject: [PATCH 3/4] Apply suggestions from code review --- docs/going-to-production.md | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/docs/going-to-production.md b/docs/going-to-production.md index 77e35b072543..96b49ade28af 100644 --- a/docs/going-to-production.md +++ b/docs/going-to-production.md @@ -70,12 +70,10 @@ export async function getServerSideProps({ req, res }) { ``` By default, `Cache-Control` headers will be set differently depending on how your page fetches data. -If the page is using `getServerSideProps` or `getInitialProps`, then it will use the default `Cache-Control` header configured by `next start` in order to prevent accidental caching of responses that cannot be cached. +If the page is using `getServerSideProps` or `getInitialProps`, then it will use the default `Cache-Control` header configured by `next start` in order to prevent accidental caching of responses that cannot be cached. If you want a different cache behavior while using SSR you can use `res.setHeader('Cache-Control', 'value_you_prefer')`. If the page is using `getStaticProps` or automatic static optimization, then it will have s-maxage=REVALIDATE_SECONDS, stale-while-revalidate or if revalidate is not used s-maxage=31536000, stale-while-revalidate. -If you want a different Cache-Control while using SSR you can use res.setHeader('Cache-Control', 'value_you_prefer'). - > **Note:** Your deployment provider must support edge caching for dynamic responses. If you are self-hosting, you will need to add this logic to the edge yourself using a key/value store. If you are using Vercel, [edge caching works without configuration](https://vercel.com/docs/edge-network/caching). ## Reducing JavaScript Size From 3f76c1a661c9069c13585094d025e8d018f3e6f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bal=C3=A1zs=20Orb=C3=A1n?= Date: Wed, 16 Mar 2022 11:48:20 +0100 Subject: [PATCH 4/4] Update going-to-production.md --- docs/going-to-production.md | 1 + 1 file changed, 1 insertion(+) diff --git a/docs/going-to-production.md b/docs/going-to-production.md index 96b49ade28af..c0527b966a54 100644 --- a/docs/going-to-production.md +++ b/docs/going-to-production.md @@ -68,6 +68,7 @@ export async function getServerSideProps({ req, res }) { } } ``` + By default, `Cache-Control` headers will be set differently depending on how your page fetches data. If the page is using `getServerSideProps` or `getInitialProps`, then it will use the default `Cache-Control` header configured by `next start` in order to prevent accidental caching of responses that cannot be cached. If you want a different cache behavior while using SSR you can use `res.setHeader('Cache-Control', 'value_you_prefer')`.