>_
EngineeringNotes
Back to Next.js Mastery

What is Next.js?

Next.js is a React-based full-stack framework used to build modern web applications with performance and routing optimizations built-in.

Server-side rendering (SSR)
Static site generation (SSG)
API routes (Backend support)
Out-of-the-box optimization

Developed and maintained by Vercel.

Why Next.js is Used (Problem it Solves)

React alone

React is primarily a UI library. Building production apps requires significant manual configuration:

  • • Complex Client-side Routing
  • • Manual SSR Implementation
  • • Tooling setup (Babel, Webpack)
  • • Ad-hoc performance tuning

Next.js capabilities

  • Built-in routing
  • SSR/SSG functionality
  • Integrated Backend APIs
  • Automated optimizations

Next.js = React + Backend capabilities + Rendering strategies

Key Features of Next.js

1. File-based Routing

Routes are automatically generated based on the file structure in /pages or /app directories.

/pages/index.js → / /pages/about.js → /about

2. Server-Side Rendering (SSR)

Pages are generated on the server for each request, ensuring fresh data and superior SEO.

3.

HTML is generated at build time, allowing for extreme speed and global distribution via CDNs.

4. Incremental Static Regeneration (ISR)

Allows developers to update static content without rebuilding the entire site, blending SSR and SSG.

5. API Routes

Full-stack functionality with backend endpoints manageable within the same application structure.

/api/user.js → /api/user

6. Built-in Optimization

Automatic image handling, font optimization, and intelligent code splitting out of the box.

7. Middleware Support

Execute code before a request is completed for authentication, logging, or redirection.

8. App Router

Leverages React Server Components for performance-first architecture and integrated layouts.

Next.js Architecture

Client

(Browser)

Next.js Server

(Node.js / Edge Runtime)

React Components & API Routes

Backend

(DB / External APIs)

SSR vs CSR Comparison

Client-Side Rendering (CSR)

The browser handles page rendering entirely after obtaining a minimal HTML structure and JavaScript assets.

01 [ Browser ] → Request
02 [ Server ] → Empty HTML/JS
03 [ Browser ] → Execution
04 [ UI ] → Interactive
Fast Transitions
Poor SEO

Server-Side Rendering (SSR)

The server constructs the full HTML for every request, delivering a viewable page immediately to the browser.

01 [ Browser ] → Request
02 [ Server ] → Render HTML
03 [ Browser ] → Full Page Content
04 [ UI ] → Instant Visibility
Superior SEO
High Server Load

Rendering strategy comparison

Feature MetricServer-Side (SSR)Client-Side (CSR)
Rendering LocationServer instanceUser browser
SEO CapabilitiesExcellentLimited / Poor
Initial Load SyncInstant visibilityDelayed (JS waiting)
Time to InteractiveMedium (Hydration)Fast (Final load)
Infrastructure CostVariable (High)Minimal (Cheap)

Architecture Selection Guide

Blog Platforms

SSG

Static, SEO heavy

Admin Dashboards

CSR

Highly interactive

E-commerce Sites

SSR + ISR

Dynamic & scale

Landing Pages

SSG

Maximum speed

Rendering Flow Summary

CSRClient → JS → Render
SSRServer → HTML → Client
SSGBuild → HTML → Client
ISRBuild → Serve → Rebuild

Interview-Level Key Concepts

1. Framework Distinction

React is a library. Next.js is a comprehensive framework providing built-in routing, rendering strategies, and integrated backend APIs.

2. Full-Stack Nature

Next.js is natively Full-Stack.

It unifies Frontend (React) and Backend (API routes) within a single development lifecycle.

3. Hydration Process

The process of attaching React event listeners to static HTML received from the server, making the content interactive on the client-side.

4. Pre-rendering

Pre-rendering occurs in either SSR or SSG mode, generating page content prior to client-side arrival.

5. Edge Runtime

Executes code at CDN locations physically closer to the user, significantly reducing response latency compared to traditional servers.

6. Middleware Architecture

Runs before a request is complete, enabling sophisticated authentication, intelligent redirection, and localized logging.

7. Standard Directory Structure

  • /pages Primary routing system
  • /api Serverless backend functions
  • /components Modular UI building blocks
  • /public Static asset management

8. SSR vs SSG Hooks

getServerSidePropsSSR / Dynamic
getStaticPropsSSG / Static

Platform Application Spectrum

Enterprise E-commerce
High-Traffic Blogs
SaaS Dashboards
Interactive Portfolios