The Static vs. Dynamic Dilemma
Historically, web developers had to choose between two rendering methods:
- Static Site Generation (SSG): Statically compiled pages load instantly but display stale data until the next project build.
- Server-Side Rendering (SSR): Pages load fresh data on every request but suffer from server query delays and database latency.
Next.js resolves this with Incremental Static Regeneration (ISR). ISR allows you to create static pages that re-render in the background when users request them, updating the page instantly when edits occur in your database.
Implementing ISR in Route Segments
To activate ISR in Next.js, define a revalidation time window in your page file or API handler:
// src/app/blog/[slug]/page.tsx
export const revalidate = 3600; // Revalidate page data at most once per hour
export async function generateStaticParams() {
const blogs = await fetchBlogsList();
return blogs.map((blog) => ({
slug: blog.slug,
}));
}
export default async function BlogPage({ params }: { params: { slug: string } }) {
const blog = await fetchBlogData(params.slug);
return <BlogLayout data={blog} />;
}Enhancing Core Web Vitals with ISR
ISR is a vital tool in modern web app development. Because pages are pre-compiled, edge CDN nodes distribute them instantly.
When a user requests a page, the CDN serves the cached static HTML page first. If the cache is stale, the server regenerates the page in the background. The next visitor will receive the newly compiled version, ensuring low page speeds and fresh content.
Related Capability: Learn how DUVOLABS designs and deploys world-class Web Application Development solutions for enterprise brands.
DUVOLABS