Yasin Avci

Yasin Avci

Full-Stack Developer

Paris, France

Contact me
Back to articles
Next.jsPerformanceArchitecture

Next.js: SSG, SSR, ISR — Choosing the Right Rendering Strategy

Static generation, server rendering, incremental regeneration... How to choose the right approach for your use case.

March 28, 20244 min read

Next.js offers three main rendering strategies. Understanding their differences is essential for building performant applications.

The Three Rendering Modes

SSG (Static Site Generation)

The page is generated at build time. The HTML is created once, then served as-is to every visitor.

// pages/blog/[slug].tsx
export async function getStaticPaths() {
  const posts = getAllPosts();
  return {
    paths: posts.map(post => ({ params: { slug: post.slug } })),
    fallback: false
  };
}

export async function getStaticProps({ params }) {
  const post = getPostBySlug(params.slug);
  return { props: { post } };
}

Advantages:

  • Maximum performance (pre-generated HTML)
  • Free hosting on CDN
  • Excellent for SEO

Disadvantages:

  • Data frozen until next build
  • Build time increases with number of pages

Use cases: blogs, documentation, marketing pages, portfolios.

SSR (Server-Side Rendering)

The page is generated on each request. The server executes the code and returns fresh HTML.

// pages/dashboard.tsx
export async function getServerSideProps({ req }) {
  const session = await getSession(req);
  const userData = await fetchUserData(session.userId);
  return { props: { userData } };
}

Advantages:

  • Data always up to date
  • Access to request context (cookies, headers)
  • Content personalized per user

Disadvantages:

  • Slower response time (generation on each request)
  • Requires a Node.js server
  • Higher hosting cost

Use cases: dashboards, pages with authentication, personalized content.

ISR (Incremental Static Regeneration)

The best of both worlds: static pages that regenerate automatically after a delay.

// pages/products/[id].tsx
export async function getStaticProps({ params }) {
  const product = await fetchProduct(params.id);
  return {
    props: { product },
    revalidate: 60 // Regenerate after 60 seconds
  };
}

Advantages:

  • SSG performance
  • Data updated regularly
  • No complete rebuild necessary

Disadvantages:

  • Data potentially stale during revalidation delay
  • More complex to debug

Use cases: e-commerce, news sites, product catalogs.

How to Choose?

| Criterion | SSG | SSR | ISR | |-----------|-----|-----|-----| | Static data | ✅ | ❌ | ⚠️ | | Real-time data | ❌ | ✅ | ⚠️ | | Performance | ⭐⭐⭐ | ⭐ | ⭐⭐⭐ | | SEO | ⭐⭐⭐ | ⭐⭐⭐ | ⭐⭐⭐ | | Personalization | ❌ | ✅ | ❌ |

My Decision Tree

  1. Does data change often?

    • No → SSG
    • Yes, every hour → ISR
    • Yes, on each request → SSR
  2. Is content personalized per user?

    • Yes → SSR (or client-side fetching)
    • No → SSG or ISR
  3. How many distinct pages?

    • < 1000 → SSG no problem
    • 10000 → ISR with fallback: 'blocking'

Advanced Patterns

Hybrid: Static + Client-Side

For an e-commerce product page, combine:

  • SSG/ISR for main content (name, description, images)
  • Client fetching for dynamic data (stock, price)
// Statically generated page
export async function getStaticProps({ params }) {
  const product = await fetchProduct(params.id);
  return { props: { product }, revalidate: 3600 };
}

// Component with real-time data
function ProductPage({ product }) {
  const { data: stock } = useSWR(`/api/stock/${product.id}`);

  return (
    <div>
      <h1>{product.name}</h1>
      <p>{product.description}</p>
      <span>In stock: {stock?.quantity ?? '...'}</span>
    </div>
  );
}

On-demand Revalidation

Trigger regeneration manually via an API:

// pages/api/revalidate.ts
export default async function handler(req, res) {
  await res.revalidate('/products/' + req.body.productId);
  return res.json({ revalidated: true });
}

Useful when an admin updates a product in the CMS.

Common Mistakes

  1. Using SSR for static content — waste of server resources
  2. SSG with too many pages — 30+ minute builds
  3. Forgetting fallback — non-generated pages returning 404
  4. ISR with revalidate too short — unnecessary server load

Conclusion

There's no universal strategy. The right approach depends on your constraints: update frequency, page volume, personalization needs.

Start with SSG. Move to ISR if data changes. Reserve SSR for cases that really need it.