Skip to content

How can you implement Incremental Static Regeneration (ISR) with dynamic parameters in the new App Router of Next.js, while ensuring atomic cache invalidation and minimizing stale content for high-traffic pages? What are the trade-offs between using revalidate tags, on-demand revalidation APIs, and edge middleware for this use case? #81243

Answered by Dronzer2code
SoumyaEXE asked this question in Help
Discussion options

You must be logged in to vote

In Next.js App Router, for dynamic pages like news/[slug], you fetch data using fetch in your Server Components.

  1. Time-based ISR (revalidate in fetch):
    Add revalidate: 3600 (1 hour) to your fetch call. Next.js serves the old page instantly, then fetches new data in the background. Pros: Simple. Cons: Content can be stale for up to an hour.

  2. On-Demand Revalidation (revalidateTag):
    This is your best friend for freshness. Tag your fetch call: { next: { tags: ['article-id-123'] } }. When your article is updated in your CMS, tell your backend to hit a special Next.js API route (a Route Handler) that calls revalidateTag('article-id-123'). Pros: Near-instant updates, atomic (full page replaced…

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by SoumyaEXE
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Help
Labels
None yet
2 participants