Pages with getServerSideProps always "Miss from cloudfront"
See original GitHub issueDescribe the bug
Hi, pages with getServerSideProps always “Miss from cloudfront” instead pages with getInitialProps correctly give “Hit from cloudfront”.
this is my default cache behaviour:
cloudfront:
defaults:
ttl: ${env.DEFAULT_BH_TTL}
allowedHttpMethods: ['HEAD', 'GET']
viewerProtocolPolicy: 'redirect-to-https'
forward:
headers: 'none'
cookies: 'all'
queryString: true
lambda@edge:
viewer-request: ${env.REWRITE_LAMBDA_ARN}
In the response there is:
Cache-Control: private, no-cache, no-store, max-age=0, must-revalidate
Versions
- OS/Environment: Linux
- @sls-next/serverless-component version: 1.18.0
- Next.js version: 10.0.3
Checklist
- You have reviewed the README and FAQs, which answers several common questions.
- Please first try using the most recent
latest
oralpha
@sls-next/serverless-component
release version, which may have already fixed your issue or implemented the feature you are trying to use. Note that the oldserverless-next.js
component and theserverless-next.js
plugin are deprecated and no longer maintained.
Issue Analytics
- State:
- Created 3 years ago
- Comments:5
Top Results From Across the Web
Troubleshoot the CloudFront distribution “X-Cache:Miss from ...
To diagnose and troubleshoot a "X-Cache:Miss from CloudFront" response, check the following: Which edge location is receiving the requests?
Read more >CloudFront headers in Next.js missing when navigating to page
The map will load using the defaults for the userLocation , because the CloudFront headers are coming through as undefined in getServerSideProps ......
Read more >Data Fetching: getServerSideProps - Next.js
First, immediately show the page without data. Parts of the page can be pre-rendered using Static Generation. You can show loading states for...
Read more >A Complete Guide To Incremental Static Regeneration (ISR ...
Incremental Static Regeneration (ISR) is a new evolution of the Jamstack, allowing you to update static content instantly without needing a ...
Read more >Serverless Next.js Component - Serverless Framework: Plugins
Statically optimised pages compiled by next are served from CloudFront edge locations ... [x] Opt-in to server-side rendering (SSR) via getServerSideProps .
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Yes this is expected by default as it should be server-side rendered and not cached as content is dynamic. This component does not set any
cache-control
headers for you for server-side rendered pages. I believe thecache-control
header for pages withgetServerSideProps
is set by Next.js toprivate, no-cache, no-store, max-age=0, must-revalidate
. So it won’t be cached by CloudFront (unless you had set a min TTL of more than 0).I did notice however that if you use
getInitialProps
, Next.js doesn’t seem to set a cache control header. In which case, CloudFront will cache it for whatever TTLs that you set. If you had it to cache for 60 seconds or whatever as the default TTL, then it will be a hit from CloudFront for 60 seconds.The workaround would be to set
cache-control
headers yourself ingetServerSideProps
if you wish to cache it for longer.thank you very much I understand!