#disable stale response in ISR
1 messages · Page 1 of 1 (latest)
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:
- Set a very low revalidation time: You can set the
revalidateoption to a very low value, like 1 second, in yourgetStaticPropsfunction. 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
}
}
- 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.revalidateAPI 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.