question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Different cacheing behaviour then the expected from getStaticProps function

See original GitHub issue

Which Package & Your Environment

Expected Behaviour

I am expecting to have the same behavior in the browser as mentioned in code. immutable https://github.com/jthegedus/firebase-gcp-examples/blob/master/functions-nextjs/pages/blog/[pid].js

image

Actual Behaviour

But, getting this header in response stale-while-revalidate Due to which firebase CDN is not always caching this page. ([pid].js) and some times I am getting cache MISS.

image

initially (just after deployment) not even getting cache headers. image

Possible Solution

Probably a correct response header through server.js file.

Context

I have a requirement where my app will have 40k pages and all of them gonna change on the next build. I want to cache all my pages at the CDN level until the next build.

I tried setting a response header in getServerSideProps. it works fine for me. But, my question is can I achieve this with getStaticProps. image

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:17 (11 by maintainers)

github_iconTop GitHub Comments

2reactions
jthegeduscommented, May 24, 2020

Did your Cloud Run deployment succeed? If so, make sure the region you deployed your Cloud Run service matches the region in your firebase.json.

It might also just be that you need to upgrade to Blaze payment model for your Firebase project.

I have updates to that Cloud Run example I’ll be publishing tomorrow. Mainly around deployment

Edit: yep, probably just blaze payment plan as it’s required for cloud run - https://firebase.google.com/docs/hosting/cloud-run#enable-billing

Cloud Run does have a free tier almost identical to cloud functions

1reaction
jthegeduscommented, May 31, 2020

I do not have a complete understanding of this functionality, but I believe __NEXT_DATA__ is the mechanism Next.js uses to hydrate the data for the page from the .json which is different for each SSG page. I do not think this can be replaced. Perhaps you should ask this question in the Next.js repo as you will have better feedback about what you may be able to do to stop web scraping.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Data Fetching: getStaticProps - Next.js
The getStaticProps function should return an object containing either props , redirect , or notFound followed by an optional revalidate property. props. The ......
Read more >
getStaticPaths re-imports node modules preventing caching ...
This behavior suggest that when page is requested and getStaticPaths is called, it re-imports all modules. Note: When using getStaticProps ...
Read more >
What is getStaticProps() in Nextjs? - DEV Community ‍ ‍
Whenever the page client loads the page, code inside getStaticProps executed first and, then it returns the object to the main page component....
Read more >
Next JS - Data Fetching | GetStaticProps vs GetServerSideProps
Courses: https://academy.eincode.comWe'll talk about the three unique Next.js functions you can use to fetch data for ...
Read more >
When to Use Different Data-Fetching Methods in Next.js
Then, for added efficiency, we want to cache the result and only serve ... In Next.js, the getStaticProps function implements this behavior ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found