Menu

Static Generation at Scale and ISR

Lesson 5: Static Generation at Scale and ISR

What is ISR?

Incremental Static Regeneration (ISR) lets you keep the speed of static pages while updating them after deployment, without rebuilding the whole site.

Approach Build time Freshness
Prerender every page Long for large catalogues Stale until next deploy
Fully dynamic None Always fresh, slower and costlier
ISR Prerender popular pages only Pages refresh in the background on a schedule or on demand

Example

// app/courses/[slug]/page.tsx
import { cacheLife, cacheTag } from 'next/cache';

export async function generateStaticParams() {
  const popular = await getPopularCourses(50); // Prerender the top 50 at build
  return popular.map((c) => ({ slug: c.slug }));
}

export default async function CoursePage({ params }: PageProps<'/courses/[slug]'>) {
  const { slug } = await params;
  return <CourseDetails slug={slug} />;
}

async function CourseDetails({ slug }: { slug: string }) {
  'use cache';
  cacheLife('days');
  cacheTag(`course-${slug}`);
  const course = await getCourse(slug);
  if (!course) notFound();
  return <article><h1>{course.title}</h1></article>;
}

How it works

  1. At build time, the 50 popular courses are prerendered.
  2. Any other slug is rendered on its first request, then cached. Since Next.js 16.3, with Cache Components, the first visitor sees an instant loading shell while the full page is prerendered in the background.
  3. Each page refreshes in the background once its revalidate time passes (days = once a day).
  4. Editing a course calls updateTag('course-<slug>'), so that page refreshes immediately.

Without Cache Components (older model you will see in existing projects):

export const revalidate = 86400; // Regenerate at most once a day

const res = await fetch(url, { next: { revalidate: 3600, tags: ['courses'] } });

Common mistakes

Mistake Effect Fix
Returning every record from generateStaticParams Very long builds Prerender popular pages; render the rest on demand
Expecting ISR with static export (output: 'export') Not supported Use a Node.js server or a platform that supports ISR
Short revalidation on rarely changing pages Wasted server work Match the lifetime to how often content changes

Key takeaways

  • Prerender the most-visited pages at build time; render the rest on first visit.
  • Combine a lifetime with tags so pages stay fast and update when content changes.

Try it: Prerender your top five courses with generateStaticParams, visit a sixth course, then run the build again and note how the output changes.


Nextjs Tutorial

J

Jebasta





Get in Touch For Details