Revalidation strategies help keep your website data fresh by updating it automatically after a set time. This way, users see recent content without waiting for a full rebuild.
Revalidation strategies (time-based) in NextJS
export async function getStaticProps() { // fetch data here return { props: { data }, revalidate: 10, // seconds }; }
The revalidate value is in seconds and tells Next.js how often to update the page.
Next.js will serve the cached page until the revalidation time passes, then update in the background.
export async function getStaticProps() { return { props: { message: 'Hello!' }, revalidate: 60, // update every 60 seconds }; }
export async function getStaticProps() { return { props: { time: new Date().toISOString() }, revalidate: 5, // update every 5 seconds }; }
This Next.js page shows the time it was generated. It updates automatically every 10 seconds using time-based revalidation.
import React from 'react'; export async function getStaticProps() { const currentTime = new Date().toISOString(); return { props: { currentTime }, revalidate: 10, // revalidate every 10 seconds }; } export default function TimePage({ currentTime }) { return ( <main> <h1>Current Time</h1> <p>The page was generated at:</p> <time dateTime={currentTime}>{currentTime}</time> </main> ); }
Revalidation happens in the background, so users see the old page until the new one is ready.
If you set revalidate to 0 or omit it, the page will not update automatically.
Use time-based revalidation to balance performance and freshness.
Time-based revalidation updates static pages automatically after a set number of seconds.
This keeps content fresh without rebuilding the whole site manually.
Set revalidate in getStaticProps to control update frequency.