Revalidation vs On-Demand Revalidation

In revalidation, controls when cached pages refresh. It ensures users see updated data without losing performance.

What is Revalidation?

Revalidation automatically refreshes cached data after a fixed time. Next.js rebuilds the page in the background when the cache expires.

export const revalidate = 60; // refresh every 60 seconds

After 60 seconds, the next visitor triggers a fresh server render.

What is On-Demand Revalidation?

On-demand revalidation refreshes cache manually when data changes — instead of waiting for a timer.

async function updateData() {
  "use server";

  await saveChanges();
  revalidatePath("/dashboard");
}

The cache clears instantly after the update.

Why use them?

Key Difference

Real-World Example

A news site updates articles every minute automatically, while an admin dashboard refreshes immediately after publishing new content.

Interview Tip

Revalidation refreshes cached content automatically by time, while on-demand revalidation manually invalidates cache after data updates.