#disable stale response in ISR

1 messages · Page 1 of 1 (latest)

austere quarry
#

is it possible to disable stale reponses when using ISR?

knotty gateBOT
#

Hi @austere quarry. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the knowledge sources provided, it does not appear to be possible to completely disable stale responses when using Incremental Static Regeneration (ISR) in Next.js. ISR is designed to serve stale content while revalidating in the background to improve performance and reduce server load.

However, there are a few approaches you can consider to minimize stale responses:

  1. Set a very low revalidation time: You can set the revalidate option to a very low value, like 1 second, in your getStaticProps function. This will cause the page to be revalidated very frequently, reducing the likelihood of serving stale content. For example:
export const getStaticProps: GetStaticProps<Props> = async ({ params }) => {
  // ... fetch data ...
  return {
    props: { /* your props */ },
    revalidate: 1, // Revalidate every second
  }
}
  1. Use on-demand revalidation: Next.js supports on-demand revalidation, which allows you to trigger a revalidation programmatically. This can be useful if you want to update the content immediately when certain events occur. You can implement this using the res.revalidate API in Next.js.

Next.js Documentation mentions:

Next.js will invalidate the cache when a request comes in, at most once every 60 seconds.

It's important to note that completely disabling stale responses would negate many of the benefits of ISR, such as improved performance and reduced server load. The stale-while-revalidate pattern is a core part of how ISR functions.

#

If you absolutely need to ensure fresh data on every request, you might want to consider using server-side rendering (SSR) instead of ISR. However, this comes with its own trade-offs in terms of performance and server load.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: