Static (SSG) vs Dynamic (SSR) Rendering & generateStaticParams
Static (SSG) vs Dynamic (SSR) Rendering & generateStaticParams
Next.js automatically determines whether a route should be rendered statically at build time (Static Site Generation - SSG) or dynamically on every user request (Server-Side Rendering - SSR). For dynamic routes with parameters, generateStaticParams unlocks blazing static performance.
1. Static vs Dynamic Rendering
- Static Rendering (Default): Routes are rendered into HTML at build time (
npm run build) or during background revalidation. Resulting files are cached globally on edge CDNs for near-zero millisecond response times. - Dynamic Rendering: Routes are rendered on the server for each individual user request. Automatically triggered when using Dynamic Functions (
cookies(),headers(),searchParams).
2. Dynamic Functions Triggering Dynamic Rendering
If a component uses information specific to an incoming user request, Next.js automatically opts that route into Dynamic Rendering:
cookies()fromnext/headersheaders()fromnext/headers- Accessing
searchParamsinpage.tsx
3. Prerendering Dynamic Routes with generateStaticParams
For dynamic paths like app/courses/[slug]/page.tsx, Next.js doesn't know what slugs exist at build time unless you specify them. generateStaticParams queries your database during build time to generate static HTML pages for all known slugs!
4. The Dynamic Params Option (dynamicParams)
Control what happens when a user visits a dynamic slug that was NOT generated at build time:
Multiple Choice Questions
generateStaticParams function do in dynamic routes?cookies() or headers() from next/headers?export const dynamicParams = false; in a page do?npm run build output indicates that a route has been statically pre-rendered?Server Actions ("use server"): Type-Safe Mutations Without API Endpoints
Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
Related Lessons
Practice Quiz
Test your understanding of this lesson with 5 questions. Each question has one correct answer.