Next.js Fundamentals
what Next.js is
Next.js is a React-based framework created by Vercel (formerly ZEIT). It was first released in 2016. Unlike React, which is a UI library, Next.js is a full-stack framework that provides routing, rendering strategies, and performance optimizations out of the box.
Next.js uses React as its core rendering layer, but extends it with server-side capabilities and build-time optimizations.
why Next.js was created
React was designed as a client-side UI library. Its responsibility is to describe how the UI changes in response to state and props. It intentionally does not solve problems such as:
- how pages are routed
- how content is rendered before JavaScript loads
- how to handle SEO
- how to optimize initial load performance
- how to handle server-side data fetching
As React applications grew larger and more product-facing, teams had to build custom solutions for these problems using additional tooling and infrastructure.
Next.js was created to standardize and simplify these patterns by providing a framework that solves them in a consistent, production-ready way.
why react alone is not enough in some cases
A typical React application renders entirely in the browser:
- the browser downloads a mostly empty HTML file
- JavaScript is loaded
- React executes and renders the UI
This approach is known as client-side rendering (CSR).
While CSR works well for highly interactive applications, it has drawbacks:
- slow first contentful paint
- poor SEO for content-heavy pages
- blank screens while JavaScript loads
- extra work required for social sharing previews
For applications where performance, discoverability, or content visibility matter, CSR alone is often insufficient.
what problem Next.js solves
Next.js addresses these limitations by enabling multiple rendering strategies:
- server-side rendering (SSR)
- static site generation (SSG)
- incremental static regeneration (ISR)
This allows developers to choose the most appropriate rendering model per page, rather than forcing a single approach for the entire application.
browser vs server responsibilities
in a traditional React app (CSR)
- rendering happens in the browser
- the server serves static assets only
- SEO relies on JavaScript execution
in a Next.js app
- the server can render HTML
- data can be fetched on the server
- the browser hydrates the HTML and adds interactivity
This separation allows Next.js to optimize both initial load and interactivity.
why SEO matters
Search engines prioritize:
- fast-loading pages
- immediately available content
- clean, crawlable HTML
Although modern search engines can execute JavaScript, doing so is:
- slower
- less reliable
- deferred compared to HTML parsing
Pages that ship meaningful HTML early are indexed more reliably and rank better.
server-side rendering (SSR)
Server-side rendering means generating HTML for a page on the server for each request.
flow:
- request arrives
- server fetches data
- React renders HTML
- HTML is sent to the browser
- browser hydrates the page
SSR is useful when:
- data changes frequently
- content must be fresh on every request
- SEO is critical
trade-offs:
- higher server cost
- slower response compared to static files
example:
// pages/product.tsx
export async function getServerSideProps(context) {
// runs on the server for every request
const res = await fetch(`https://api.example.com/product/${context.params.id}`);
const product = await res.json();
return {
props: { product }
};
}
export default function Product({ product }) {
return (
<div>
<h1>{product.name}</h1>
<p>{product.description}</p>
</div>
);
}
static site generation (SSG)
Static site generation means generating HTML at build time.
flow:
- pages are rendered during build
- HTML files are stored on a CDN
- requests are served instantly
SSG is ideal when:
- content changes infrequently
- pages are content-heavy
- performance is a top priority
Next.js also supports incremental static regeneration (ISR), allowing static pages to be updated after deployment without rebuilding the entire site.
why google prefers HTML
HTML allows search engines to:
- index content immediately
- avoid executing JavaScript
- understand page structure reliably
Although Google can execute JavaScript, it does so in a secondary rendering pass, which may delay indexing and ranking.
Providing pre-rendered HTML improves:
- crawl efficiency
- ranking stability
- social sharing previews
how Next.js improves performance
Next.js includes several built-in performance optimizations:
1. code splitting per page
Each page only loads the JavaScript it needs:
pages/
home.tsx → only loads home.js
about.tsx → only loads about.js
blog.tsx → only loads blog.js
2. automatic static optimization
Next.js automatically determines which pages can be statically generated.
3. image optimization
import Image from 'next/image';
<Image
src="/photo.jpg"
width={800}
height={600}
alt="description"
/>
automatic:
- responsive images
- lazy loading
- modern formats (WebP, AVIF)
- size optimization
4. prefetching of linked pages
Links in the viewport are prefetched automatically:
import Link from 'next/link';
<Link href="/about">About</Link>
// prefetched when visible
5. server-side data fetching
Data can be fetched on the server, reducing client-side requests.
when to use Next.js
Next.js is a good choice when:
- ✅ SEO is important
- ✅ initial load performance matters
- ✅ pages are content-driven
- ✅ you want server-side data fetching
- ✅ you want a production-ready React framework
it may be unnecessary when:
- ❌ the app is purely internal
- ❌ SEO does not matter
- ❌ the app is highly interactive with minimal content
hydration explained
Hydration is the process where Next.js attaches React event handlers to server-rendered HTML.
flow:
- server renders HTML - full content visible
- HTML sent to browser - user sees content
- JavaScript loads - in parallel
- React hydrates - adds interactivity
- page becomes interactive - buttons work, state updates
why hydration matters:
- users see content before JavaScript loads
- progressive enhancement
- best of both worlds: fast initial load + full interactivity
summary
Next.js is a React framework created to solve rendering, performance, and SEO limitations of client-side React applications. By supporting server-side and build-time rendering strategies, it enables faster, more discoverable, and more scalable web applications without requiring custom infrastructure.
core benefits:
- multiple rendering strategies (SSR, SSG, ISR)
- improved SEO through pre-rendered HTML
- better performance via code splitting and optimization
- production-ready features out of the box
- enhanced developer experience with file-based routing
when to choose Next.js:
- content-driven applications
- SEO-critical projects
- performance-sensitive sites
- teams wanting a complete framework
when to stick with React:
- internal tools
- admin panels
- highly interactive apps where SEO doesn't matter
- projects that need minimal framework overhead