Next.js course ยท Module 1: Next.js Configuration

Rendering in Next.js - Overview of Strategies

6 min read ยท
In this lesson8

In Quantum Metropolis, information reaches residents in different ways - holographic screens on streets display content in real time, information boards generate content in advance, and personal terminals fetch data on demand. Similarly, Next.js offers several page rendering strategies, each with its own use case.

In this chapter, you'll learn about the four main rendering strategies in Next.js. We won't go into deep technical details - that's a topic for module 5. For now, we want you to understand that these strategies exist and know when each of them makes sense.

What is Rendering?

Rendering is the process of converting React code (JSX) into HTML that the browser can display to the user. The key question is: where and when does this process take place?

// This React component...
export default function Hello() {
  return <h1>Welcome to Quantum Metropolis!</h1>;
}

// ...gets converted to HTML:
// <h1>Welcome to Quantum Metropolis!</h1>

Depending on the chosen strategy, this conversion can happen:

  • On the server - before the page reaches the browser
  • In the browser - after downloading JavaScript code
  • During building - even before the server is started

SSR - Server-Side Rendering

Imagine that in Quantum Metropolis, a holographic screen generates an image in the control center and transmits the finished hologram for display. The user sees a complete image immediately after opening the transmission.

SSR means the server renders the HTML page with every user request. When someone visits a page, the server:

  1. Fetches the necessary data (from a database, API)
  2. Generates complete HTML
  3. Sends the finished page to the browser
// Server Component in Next.js - rendered on the server by default
export default async function DashboardPage() {
  // Data fetched with EVERY request
  const stats = await fetch('https://api.quantum.com/stats', { cache: 'no-store' });
  const data = await stats.json();

  return (
    <div>
      <h1>Quantum Panel</h1>
      <p>Active users: {data.activeUsers}</p>
      <p>Last update: {data.timestamp}</p>
    </div>
  );
}

The cache: 'no-store' option is required here: without it (and without request-time APIs such as cookies()), Next.js renders the page once, during next build.

When to use SSR?

  • When data changes frequently (e.g., user dashboard, shopping cart)
  • When content must be current on every refresh
  • When you need SEO for dynamic content

SSG - Static Site Generation

In Quantum Metropolis, information boards with schedules are printed once a day and posted at stops. They don't change every second - they are prepared in advance.

SSG means HTML pages are generated during application building (next build), not with every request. Ready pages are served instantly from CDN.

// Page generated statically during build
export default function AboutPage() {
  return (
    <div>
      <h1>About Quantum Metropolis</h1>
      <p>Founded in 2150 as a center for future technologies.</p>
      <p>Population: 12 million residents.</p>
    </div>
  );
}
// This page doesn't need dynamic data
// Next.js will generate it once during 'next build'

When to use SSG?

  • Blog, documentation, "About Us" page
  • Content that rarely changes
  • When maximum loading speed is the priority

CSR - Client-Side Rendering

Personal terminals of Quantum Metropolis residents download raw data and render the interface locally - each terminal creates its own image on its screen.

CSR means that the data (and in a classic SPA the whole interface) is fetched and rendered in the browser. In Next.js even a component with "use client" is pre-rendered to HTML on the server on the first visit and then hydrated: in the example below the server sends the chat heading, and the browser fetches the messages.

"use client";

import { useState, useEffect } from 'react';

export default function LiveChat() {
  const [messages, setMessages] = useState([]);

  useEffect(() => {
    // Data fetched in the browser after component loads
    fetch('/api/messages')
      .then(res => res.json())
      .then(data => setMessages(data));
  }, []);

  return (
    <div>
      <h2>Quantum Chat</h2>
      {messages.map(msg => (
        <p key={msg.id}>{msg.text}</p>
      ))}
    </div>
  );
}

When to use CSR?

  • Interactive elements (chat, forms, real-time dashboards)
  • When SEO isn't needed for a given section
  • When the component requires access to browser APIs (localStorage, geolocation)

ISR - Incremental Static Regeneration

In Quantum Metropolis, information boards have an automatic update mode - they're static, but at a set interval (e.g., every hour) the system checks for new data and generates an updated version.

ISR combines the advantages of SSG (speed) with SSR (freshness). The page is generated statically, and once the set time has passed, the first request triggers its regeneration in the background (that request still gets the previous version).

// Page with ISR - static, regenerated in the background at most once every 60 seconds
export default async function ProductsPage() {
  const res = await fetch('https://api.quantum.com/products', {
    next: { revalidate: 60 } // Background regeneration at most once every 60 seconds
  });
  const products = await res.json();

  return (
    <div>
      <h1>Quantum Store Products</h1>
      {products.map(p => (
        <div key={p.id}>
          <h3>{p.name}</h3>
          <p>{p.price} credits</p>
        </div>
      ))}
    </div>
  );
}

When to use ISR?

  • Online store (products change, but not every second)
  • Page with articles/news
  • When you want SSG speed but with updates

Simple Mental Diagram - Which Strategy to Choose?

Here's a simple decision scheme to help you choose the right strategy:

Does the content change with every request?
  YES -> Do you need SEO?
          YES -> SSR (server rendering)
          NO  -> CSR (browser rendering)
  NO  -> Does the content change from time to time?
          YES -> ISR (static with regeneration)
          NO  -> SSG (fully static)
StrategySpeedData FreshnessSEOUsage Example
SSGFastestData from build timeYesBlog, documentation
ISRVery fastRefreshed at most every X secondsYesStore, news
SSRFastAlways currentYesDashboard, profile
CSRDepends on clientFetched liveNoChat, forms

What's Next?

In module 5 of this course, we'll dive into the technical details of each rendering strategy. You'll learn:

  • How to precisely configure SSR and ISR in App Router
  • How to optimize rendering performance
  • How to combine different strategies in a single application
  • Advanced patterns with React Server Components

For now, the most important thing is to remember that Next.js gives you a choice - you don't have to render everything the same way. Each page, and even each component, can use a different strategy.

Summary

Quantum Metropolis shows us that different information delivery systems have different applications. Similarly in Next.js:

  1. SSR - server renders the page with every request (data always current)
  2. SSG - page generated once during building (fastest)
  3. CSR - browser renders the page after downloading JS (interactivity)
  4. ISR - static page with automatic regeneration (compromise between speed and freshness)

Understanding these strategies is the foundation of working with Next.js. In the following modules, you'll apply them in practice, building increasingly advanced applications in Quantum Metropolis.

Code for this lesson: App.tsx
import React, { useState } from 'react';

// Interactive overview of Next.js rendering strategies
const RenderingOverview = () => {
  const [selected, setSelected] = useState<string | null>(null);

  const strategies = [
    {
      id: 'ssr',
      name: 'SSR',
      fullName: 'Server-Side Rendering',
      icon: '',
      color: '#7c4dff',
      speed: 'Fast',
      freshness: 'Always up-to-date',
      seo: true,
      description: 'Server renders the page on EVERY request. Data is always fresh.',
      useCase: 'Dashboard, user profile, shopping cart',
      code: 'export default async function Page() {\n  const data = await fetch(url);\n  return <div>{data.title}</div>;\n}',
    },
    {
      id: 'ssg',
      name: 'SSG',
      fullName: 'Static Site Generation',
      icon: '',
      color: '#4caf50',
      speed: 'Fastest',
      freshness: 'From build time',
      seo: true,
      description: 'Pages generated ONCE during build. Served from CDN.',
      useCase: 'Blog, documentation, About Us page',
      code: 'export default function About() {\n  return <div>Static content</div>;\n}',
    },
    {
      id: 'csr',
      name: 'CSR',
      fullName: 'Client-Side Rendering',
      icon: '',
      color: '#ff9800',
      speed: 'Depends on the client',
      freshness: 'Fetched live',
      seo: false,
      description: 'Browser downloads JS and renders the page itself.',
      useCase: 'Chat, forms, interactive dashboards',
      code: '"use client";\nimport { useState } from "react";\n// Rendering in the browser',
    },
    {
      id: 'isr',
      name: 'ISR',
      fullName: 'Incremental Static Regeneration',
      icon: '',
      color: '#e91e63',
      speed: 'Very fast',
      freshness: 'Every X seconds',
      seo: true,
      description: 'Static page with automatic regeneration at set intervals.',
      useCase: 'Store, articles, news',
      code: 'const res = await fetch(url, {\n  next: { revalidate: 60 }\n});',
    },
  ];

  const active = strategies.find(s => s.id === selected);

  return (
    <div style={{ background: '#0f0f23', minHeight: '100vh', padding: '20px', color: '#fff', fontFamily: 'sans-serif' }}>
      <h1 style={{ color: '#64ffda', textAlign: 'center', marginBottom: '8px' }}>
        Next.js Rendering Strategies
      </h1>
      <p style={{ textAlign: 'center', color: '#888', marginBottom: '24px' }}>
        Click a strategy to see details
      </p>

      <div style={{ display: 'grid', gridTemplateColumns: 'repeat(4, 1fr)', gap: '12px', maxWidth: '800px', margin: '0 auto 24px' }}>
        {strategies.map(s => (
          <button key={s.id} onClick={() => setSelected(s.id)}
            style={{ padding: '16px', background: selected === s.id ? s.color : 'rgba(255,255,255,0.05)',
              border: selected === s.id ? 'none' : '1px solid #333', borderRadius: '10px',
              color: '#fff', cursor: 'pointer', textAlign: 'center', transition: 'all 0.2s' }}>
            <div style={{ fontSize: '2rem' }}>{s.icon}</div>
            <div style={{ fontWeight: 'bold', marginTop: '4px' }}>{s.name}</div>
            <div style={{ fontSize: '0.7rem', color: selected === s.id ? '#fff' : '#888' }}>{s.fullName}</div>
          </button>
        ))}
      </div>

      {active && (
        <div style={{ maxWidth: '800px', margin: '0 auto', background: 'rgba(255,255,255,0.05)',
          borderRadius: '12px', padding: '24px', border: '1px solid ' + active.color }}>
          <h2 style={{ color: active.color, marginBottom: '12px' }}>{active.icon} {active.fullName}</h2>
          <p style={{ color: '#b0bec5', marginBottom: '16px' }}>{active.description}</p>

          <div style={{ display: 'grid', gridTemplateColumns: '1fr 1fr 1fr', gap: '12px', marginBottom: '16px' }}>
            <div style={{ background: 'rgba(0,0,0,0.3)', padding: '12px', borderRadius: '8px', textAlign: 'center' }}>
              <div style={{ color: '#888', fontSize: '0.8rem' }}>Speed</div>
              <div style={{ color: '#64ffda', fontWeight: 'bold' }}>{active.speed}</div>
            </div>
            <div style={{ background: 'rgba(0,0,0,0.3)', padding: '12px', borderRadius: '8px', textAlign: 'center' }}>
              <div style={{ color: '#888', fontSize: '0.8rem' }}>Freshness</div>
              <div style={{ color: '#64ffda', fontWeight: 'bold' }}>{active.freshness}</div>
            </div>
            <div style={{ background: 'rgba(0,0,0,0.3)', padding: '12px', borderRadius: '8px', textAlign: 'center' }}>
              <div style={{ color: '#888', fontSize: '0.8rem' }}>SEO</div>
              <div style={{ color: active.seo ? '#4caf50' : '#f44336', fontWeight: 'bold' }}>{active.seo ? 'Yes' : 'No'}</div>
            </div>
          </div>

          <div style={{ background: '#0d1117', padding: '12px', borderRadius: '8px', marginBottom: '12px' }}>
            <pre style={{ color: '#64ffda', margin: 0, fontSize: '13px', whiteSpace: 'pre-wrap' }}>{active.code}</pre>
          </div>

          <p style={{ color: '#888', fontSize: '0.9rem' }}>
            <strong style={{ color: '#7c4dff' }}>Use when:</strong> {active.useCase}
          </p>
        </div>
      )}

      {!active && (
        <div style={{ textAlign: 'center', color: '#555', paddingTop: '40px' }}>
          Select a rendering strategy above
        </div>
      )}
    </div>
  );
};

export default RenderingOverview;

Docs entries used in this lesson

Spotted a mistake in this lesson?

Check yourself

Answer the questions from this lesson. Pick an answer to see right away whether it is correct.

  1. 1. Which rendering strategy generates HTML pages during the application build (next build)?

  2. 2. What characterizes ISR (Incremental Static Regeneration) in Next.js?

  3. 3. How do you define environment variables accessible on the client side in Next.js?

  4. 4. What does the 'use client' directive at the beginning of a file mean in Next.js?

  5. 5. Which tool is NOT part of a typical Next.js development environment?

  6. 6. Which directory in Next.js (App Router) contains page definitions and routes?

  7. 7. Which Next.js feature automatically splits JavaScript code into smaller bundles loaded on demand?

Hands-on tasks in the game

  • Click in order

    Arrange the correct path to the layout file in App Router

  • Vertical ordering

    Arrange the order of the component lifecycle in App Router

  • Vertical ordering

    Arrange the syntax for using the Image component from Next.js

  • Vertical ordering

    Arrange the order of the image optimization pipeline in Next.js

  • Click in order

    Arrange the correct JSX structure with a div element and an h1 heading

  • Vertical ordering

    Arrange the syntax of the getStaticProps function in the Pages Router (pages/ folder)

  • Vertical ordering

    Arrange the order of HTTP request handling in Next.js

  • Vertical ordering

    Arrange the syntax of the getServerSideProps function in the Pages Router (pages/ folder)

  • Vertical ordering

    Arrange the order of the API request flow through the proxy (formerly middleware)

  • Code editor

    Build the home page of a portfolio with the App Router (file app/page.jsx) as a default-exported Portfolio component. Follow these steps in order: 1. The main element has className="portfolio". 2. At the top, put a <nav> with three <Link> links from next/link: "Home" (/), "Projects" (/projects) and "Contact" (/contact). 3. Add an <h1> heading with your name or nickname. 4. Create a projects array with at least 2 objects { id, title } and display it in a <ul> with map: each project as an <li key={project.id}> with its title. 5. In styles.css, add a rule for the .portfolio class (for example a background and spacing).

  1. QuestionSSG Strategy in Next.js
  2. QuestionApplication of ISR
  3. QuestionClient-Side Environment Variables in Next.js
  4. Click in orderLayout File Path in App Router
  5. Put in orderLifecycle in App Router
  6. Put in orderUsing the Image Component
  7. QuestionThe 'use client' Directive in Next.js
  8. Put in orderImage Optimization Pipeline
  9. Click in orderJSX Structure with div and h1
  10. Put in ordergetStaticProps Syntax
  11. QuestionNext.js Development Environment
  12. Put in orderHTTP Request Handling
  13. QuestionPages Directory in App Router
  14. Put in ordergetServerSideProps Syntax
  15. Put in orderAPI Request Flow
  16. QuestionJavaScript Bundles Loaded on Demand
  17. Coding taskPortfolio with App Router - Step by Step
  18. Project to submitLink
  19. VideoVideo: Module Summary

Useful articles