Lesson 183 of 296
Static, dynamic, ISR and SEO metadata
What you will learn
- CSR, SSR, SSG, ISR and PPR: what each means
- What makes a Next.js route static or dynamic
- generateStaticParams
- Choosing a rendering strategy
- The Metadata API, generateMetadata, sitemaps and robots
- Images and fonts for performance and SEO
On this page
Rendering strategies
These names come up in almost every Next.js interview:
| Name | When the HTML is made | Good for | Weakness |
|---|---|---|---|
| CSR (client-side rendering) | In the browser, after JavaScript loads | Logged-in dashboards, highly interactive tools | Slow first content, weaker SEO |
| SSR (server-side rendering, dynamic) | On the server, for every request | Personalised or always-fresh pages (basket, account) | Server work on every request |
| SSG (static site generation) | Once, at build time | Marketing pages, docs, blog posts | Data can be old until the next build |
| ISR (incremental static regeneration) | At build time, then re-generated in the background after a time or on demand | Product pages, news, lesson pages | Brief staleness |
| PPR (partial pre-rendering) | Static shell at build time, dynamic parts streamed per request | Pages that are mostly static with a few personal parts | Newer; requires Cache Components |
In the App Router you do not pick these by name. Next.js decides per route based on what your code uses.
What makes a route dynamic?
A route is rendered per request if it uses request-time information:
cookies(),headers(),connection()ordraftMode()searchParamsin a page- Uncached data fetches (with Cache Components, any data not marked
"use cache")
Otherwise it can be pre-rendered at build time. The build output marks each route as static or dynamic, which is useful to check.
generateStaticParams
For dynamic routes like /lessons/[slug], tell Next.js which pages to build at build time:
type LessonMeta = { slug: string };
declare function listLessons(): Promise<LessonMeta[]>;
export async function generateStaticParams(): Promise<{ slug: string }[]> {
const lessons = await listLessons();
return lessons.map((l) => ({ slug: l.slug }));
}Each returned object becomes one pre-built page. Pages not in the list can still be generated the first time someone visits them (unless you set export const dynamicParams = false, which returns 404 for unknown slugs).
ISR in practice
In the older model: export const revalidate = 3600 in a page re-generates it at most once per hour. On-demand: call revalidatePath or revalidateTag from a server action or a webhook route handler when the CMS publishes changes. With Cache Components: "use cache" with cacheLife and tags (Lesson 179) gives the same result.
Choosing a strategy
- Is the page the same for everyone? Make it static, and revalidate when data changes.
- Does a small part depend on the user? Keep the page static and put that part in Suspense as a dynamic island (PPR) or fetch it on the client.
- Is it completely personal and behind a login? Dynamic rendering is fine (SEO does not matter there).
- Does it need real-time updates? Static or dynamic shell, plus client fetching or WebSockets (Part 15).
SEO metadata
Static metadata: export a metadata object from a layout or page:
import type { Metadata } from "next";
export const metadata: Metadata = {
title: { default: "JobPrep", template: "%s | JobPrep" },
description: "A free course from zero to job-ready full stack developer.",
metadataBase: new URL("https://jobprep.example"),
openGraph: { type: "website", siteName: "JobPrep" }
};The template means a page with title: "React" gets "React | JobPrep".
Dynamic metadata: generateMetadata for pages that depend on data:
import type { Metadata } from "next";
type LessonDetail = { title: string; summary: string };
declare function getLesson(slug: string): Promise<LessonDetail | null>;
export async function generateMetadata({ params }: { params: Promise<{ slug: string }> }): Promise<Metadata> {
const { slug } = await params;
const lesson = await getLesson(slug);
if (!lesson) return { title: "Lesson not found" };
return {
title: lesson.title,
description: lesson.summary,
alternates: { canonical: `/lessons/${slug}` },
openGraph: { title: lesson.title, description: lesson.summary }
};
}- Next.js de-duplicates the data fetch shared with the page (use
cache()for non-fetch functions, Lesson 178). alternates.canonicaltells search engines the main URL of the page (Lesson 14).- Open Graph fields control the preview card when the link is shared on LinkedIn, WhatsApp or Facebook. An
opengraph-image.tsxfile can generate the preview image with code.
Sitemap and robots
Special files generate these automatically:
import type { MetadataRoute } from "next";
export default function sitemap(): MetadataRoute.Sitemap {
return [
{ url: "https://jobprep.example/", changeFrequency: "weekly", priority: 1 },
{ url: "https://jobprep.example/lessons", changeFrequency: "daily", priority: 0.8 }
];
}That is app/sitemap.ts. Similarly app/robots.ts returns rules such as { rules: { userAgent: "*", allow: "/", disallow: "/dashboard" }, sitemap: "https://jobprep.example/sitemap.xml" }. Structured data (JSON-LD, Lesson 14) can be added with a <script type="application/ld+json"> in a page.
Images and fonts
next/image(<Image>): resizes images per device, serves modern formats such as WebP and AVIF, lazy-loads by default, and requires width and height (orfill) to prevent layout shift. Use thepriorityprop (calledpreloadin newer versions) for the main hero image, which is usually the LCP element (Lesson 86).next/font: downloads Google or local fonts at build time and serves them from your own domain, with no layout shift and no request to Google from the visitor's browser.
How to say it in an interview
"CSR renders in the browser, SSR on every request, SSG once at build time, ISR at build time with background regeneration, and PPR combines a static shell with streamed dynamic parts. In the App Router a route becomes dynamic when it uses request data like cookies, headers or searchParams, or uncached data; otherwise it is pre-rendered, and generateStaticParams lists which dynamic pages to build. I choose static with on-demand revalidation for shared content, and dynamic islands for personal parts. For SEO I use the metadata object and generateMetadata with canonical URLs and Open Graph, sitemap.ts and robots.ts, next/image for sized optimised images and next/font for fonts without layout shift."
Key words
| Word | Meaning |
|---|---|
| CSR | Rendering in the browser |
| SSR | Rendering on the server for every request |
| SSG | Generating pages once at build time |
| ISR | Static pages re-generated in the background |
| PPR | A static shell plus streamed dynamic parts |
| generateStaticParams | Lists which dynamic route pages to pre-build |
| generateMetadata | Creates page metadata from data |
| Open Graph | Tags that control link preview cards |
| Canonical URL | The main URL of a page for search engines |
Now prove it
This lesson is complete when you pass the quiz and all three practice levels.