Full-Stack Web
Next.jsPerformanceWeb DevSEO

Demystifying Next.js Rendering Strategies: SSG, SSR, ISR & Server Actions

Sathya Seelan
Sathya Seelan
Full-Stack Developer
October 19, 2024•5 min read

“When and why to choose Static Site Generation, Server-side Rendering, or Incremental Static Regeneration for blazing fast Lighthouse scores.”

One of Next.js's defining strengths is offering multiple rendering paradigms within the exact same project. However, choosing the wrong strategy can inflate TTFB (Time to First Byte), increase hosting costs, or serve stale data.

Let's dissect each rendering model with practical production heuristics.


1. Strategy Comparison Matrix#

  • SSG (Static Site Generation): Built at build time. TTFB ~10-30ms. Exceptional SEO. Best for marketing pages, portfolios, documentation, and technical blogs.
  • ISR (Incremental Static Regeneration): Statically built and revalidated in background on schedule. Exceptional SEO. Best for high-frequency blogs and product catalogs.
  • SSR (Server-Side Rendering): Rendered on each request dynamically. Good SEO. Best for authenticated dashboards, search feeds with personalized data.
  • CSR (Client-Side Rendering): Rendered in client browser. Fast initial static shell, delayed data load. Best for private administrative panels.

2. Incremental Static Regeneration (ISR) in Action#

ISR provides the speed of static CDN hosting while updating pages automatically without rebuilding your entire site:

typescript
// pages/blog/[slug].tsx
import { GetStaticPaths, GetStaticProps } from "next";
import { getAllBlogPosts, getBlogPostBySlug } from "../../utils/blogData";

export const getStaticPaths: GetStaticPaths = async () => {
  const posts = getAllBlogPosts();
  return {
    paths: posts.map((post) => ({ params: { slug: post.slug } })),
    fallback: false, // All paths pre-rendered at build time
  };
};

export const getStaticProps: GetStaticProps = async ({ params }) => {
  const post = getBlogPostBySlug(params?.slug as string);

  if (!post) {
    return { notFound: true };
  }

  return {
    props: { post },
    revalidate: 600, // Revalidate background cache every 10 minutes
  };
};

3. Crucial Performance Rules#

  1. 01Keep Bundle Sizes Lean: Avoid importing massive utility libraries (e.g., entire lodash or heavy chart suites) in landing routes.
  2. 02Lazy-Load Framer Motion Animations: Use LazyMotion with domAnimation features to trim 30KB+ of unused animation parsing code from your main bundle.
  3. 03Optimize Asset Loading: Use modern formats (WebP/AVIF) and explicit dimensions to eliminate Cumulative Layout Shift (CLS).