Next.js – SSR, Static Generation and When to Use What
Next.js – SSR, Static Generation and Strategy
Next.js gives you several ways to serve content: statically at build time, on the server per request, or a mix with periodic revalidation. Understanding these options is key for speed, SEO, and infrastructure cost.
Static Generation (SSG)
With Static Site Generation each page is built once during next build. The result is HTML files served directly from CDN or web server. No computation on request – just file delivery.
Benefits: maximum speed, low server load, cheap hosting (even static-only), great for SEO and Core Web Vitals.
Best for: marketing pages, blog, docs, catalogs with rarely changing content. In App Router, pages are static by default unless you use dynamic functions or dynamic fetch.
Server-Side Rendering (SSR)
With Server-Side Rendering the page is generated on every request. The server runs your code, fetches data (DB, API), renders React to HTML and sends the response. Each user can get different content.
Benefits: always fresh data, room for personalization, content based on cookies or headers.
Drawbacks: higher server load, slower than a static file (still usually under a second with good infrastructure).
Best for: dashboards, personalized portals, real-time data pages, content behind auth.
Incremental Static Regeneration (ISR)
ISR is a hybrid: the page is generated statically, but after a set period (e.g. 60 seconds) the next request triggers regeneration in the background. Users always get a fast response; content updates without a full rebuild.
Good for: news sites, product catalogs with prices – when you want SSG speed and periodic updates.
App Router – How You Control It
In Next.js 13+ App Router components are Server Components by default and pages can be static. To make a page dynamic (SSR), you use dynamic functions like cookies(), headers(), or searchParams in the page, or set export const dynamic = 'force-dynamic'.
For static pages with dynamic segments (e.g. /blog/[slug]) you use generateStaticParams() – Next.js will pregenerate all combinations at build. To mix pregenerated and on-demand pages you combine generateStaticParams with dynamicParams.
Practical Choice
| Scenario | Recommendation | |----------|----------------| | Marketing, blog, landing | SSG (default in App Router) | | Frequently changing content | ISR with suitable revalidate | | Personalization, user data | SSR | | Mixed site | SSG for most pages, SSR for specific routes |
Choosing the right strategy avoids unnecessary server load and keeps loading fast and SEO-friendly where possible.
Want a site or app with Next.js? Contact us.