Next.js Developer interview question · Most asked
How do `revalidatePath` and `revalidateTag` work?
Summary
revalidatePath('/posts') invalidates cached data and rendered output for a path; revalidateTag('posts') invalidates all cached fetches/entries tagged posts. Both are called from Server Actions or Route Handlers after mutations or webhooks.
Longer Answer
Tag-based invalidation is more precise: tag the fetch (next: { tags: ['post:42'] }) and invalidate exactly what changed. On-demand revalidation via a webhook (e.g., from a CMS) keeps static pages fresh without short time-based intervals. Recent versions also add updateTag for read-your-own-writes semantics within Server Actions.
Key Points
- Path-based vs tag-based invalidation
- Call after mutations or CMS webhooks
- Tag fetches precisely
- Combine with time-based
revalidate
More most-asked Next.js Developer questions
- How does data fetching work in the App Router?
- How did caching defaults change in Next.js 15?
- What happens, step by step, when a request reaches a Next.js App Router application?
- What is Next.js and what problems does it solve on top of React?
- What are the differences between the App Router and the Pages Router?
- What is the difference between Server Components and Client Components?
- Explain the App Router file conventions: page, layout, loading, error, not-found, template and route.
- Explain SSR, SSG, ISR and CSR in Next.js.