What happens if Next.js ISR with the revalidate value is 1 second in Production?
Asked Answered
A

1

6

I work to create a company profile that has hundreds of blogs page. in nextjs I use ISR and the router is "Catch All router" which means I will create all pages & Blog in 1 file page / [[...path.js]]. and I use Revalidate 1 second to update the website.

my question is it doesn't matter if I use Revalidate value is 1 second in production to build the whole page? is it the bad practice? but so far not a problem with 1s revalidate in production.

Ambitious answered 26/5, 2021 at 0:33 Comment(0)
I
11

It's okay to set it to a number that makes sense for your use. Monitor your bill and impact on resources - make the decision based on facts. Generally speaking, blogs don't require near real-time updates - but if there is negligible impact on the bottom line - it doesn't matter.

Just know that if your site gets decent traffic, you will never stop busting cache and rebuilding pages/cache (making a lot of requests) if you have it at one second. However, this approach could be more cost effective than 1 request per user (SSR).

Objectively speaking, a few hundred pages could also build in around two to three minutes via a webhook, realistically, SSG could still be a valid option.

Here is a recap of the ISR process with a revalidation time of 1 second.

  1. Next.js can define a revalidation time per-page (e.g. 1 second).
  2. The initial request to the product page will show the cached page.
  3. The data for the blog post is updated in the CMS.
  4. Any requests to the page after the initial request and before the 1 second window will show the cached (stale) page.
  5. After the 1 second window, the next request will still show the cached (stale) page. Next.js triggers a regeneration of the page in the background.
  6. Once the page has been successfully generated, Next.js will invalidate the cache and show the updated product page. If the background regeneration fails, the old page remains unaltered.
Itinerary answered 26/5, 2021 at 1:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.