I’ve been trying to run the production build locally to verify that my pages built using SSG + ISR works as i expect it to. I saw that running locally using “netlify dev --context production” would allow me to do this as deploying the application using “netlify dev” would deploy in development mode which defaulted page generation to SSR even if the page was specified to be built using SSG + ISR.
However, using “netlify dev --context production” still results in the usage of SSR as i can see in my console that my API is being called to fetch data from my database at every page refresh when it should only happen after the revalidation timer has elapsed.
Is there any way to force the use of SSG + ISR instead of SSR?
Hi @Qing, thanks for writing in.
If you’re experiencing unexpected behavior with your production builds, it might be worth checking your Next.js configuration and Netlify build settings to ensure they align with your intended rendering strategy.
This appears to be a common misconception about the different build options available in Next.js. SSG will only generate the RSC (React Server Component) metadata that Next.js uses internally to fulfil the SSR request. Once the request is complete, the request will be cached locally in the fetch-cache folder, and on Netlify, a new blob entry will be added to the deploy store.
By default, Next.js will always use a function invocation regardless of your platform, enabling ISR to work. Within the cached request metadata is the revalidation timestamp (epoch) used to determine the Cache-Control header for the page. In the case of Netlify, this header is translated into a Netlify-CDN-Cache-Control header, with Cache-Control being updated to forbid all browser-level caching. So, every page you have will take at least one request before the CDN caches it.
If you don’t want that, you can use Next.js’s exportoutput mode, which will generate HTML files instead. However, you will then become responsible for ensuring that the cache control headers are configured, which has modest defaults.
To summarise, what you are experiencing is correct and a prevalent misconception of SSG.