Frontend
Next.js
A full-stack React framework: routing, SSR, static generation, API routes and server components.
What it is
Vercel (then Zeit) created Next.js in 2016 as a layer on top of React. It adds what React alone lacks: file-based routing, server rendering, image and font optimization, API endpoints.
The modern App Router is built on React Server Components: components run on the server by default, and client JS is added only where interactivity is needed ("use client"). Data can be read directly in server components, and mutations run through Server Actions.
Several modes are supported: SSR, SSG, ISR and partial prerendering. You can deploy to Vercel, or self-host on Node.js or Docker.
Use it when
- A React site or app that needs SEO and fast first load.
- Full stack in one repository: UI, server logic and API.
- Content and e-commerce sites mixing static and dynamic pages.
Avoid it when
- A simple static site: Astro or plain HTML is lighter.
- A separate complex backend where Next.js would be just a shell: a Vite SPA is enough.
- A team that does not want to track the framework's fast-moving APIs.
Key concepts
- App Router
- Routing by
app/folders with nested layouts,loadinganderror. - Server Components
- Components rendered on the server that do not enter the client bundle.
- Server Actions
- Server functions called from forms and the client without a separate API.
- Caching and revalidation
- Data and page caching with revalidation by time or by tag.
- Rendering modes
- SSR, SSG, ISR and streaming depending on the page.
Example
Cheat sheet
| Command or code | What it does |
|---|---|
npx create-next-app@latest | New Next.js project |
npm run dev | Dev server |
npm run build | Production build |
app/page.tsx | The page for the / route |
app/blog/[slug]/page.tsx | Dynamic route |
app/layout.tsx | Shared wrapper for pages |
'use client' | Makes a component a Client Component |
export async function GET() { } | Route Handler in route.ts |
import Link from 'next/link' | Client side navigation without a reload |
import Image from 'next/image' | Optimized images |
How to learn it
- First take the React course on ShortLesson.
- Create a project with create-next-app using the App Router and TypeScript.
- Learn file based routing: page, layout, dynamic segments.
- Tell Server Components from Client Components and know the use client directive.
- Learn to fetch data on the server and cache it as your version's docs describe.
- Add Route Handlers and Server Actions for forms and APIs.
- Set up styles, images, metadata and SEO.
- Deploy the app and read the docs for the exact version you use.
Interview questions
1. How does SSR differ from SSG?
SSR generates HTML on every request, SSG once at build time. SSG is faster and cheaper, SSR is for personalized or frequently changing data. ISR lets you refresh static pages on a schedule.
2. What are Server Components?
Components that run only on the server. They can read a DB or API directly in code and add no JS to the browser. Interactive parts go into client components.
3. When do you need "use client"?
When a component uses state, effects, event handlers or browser APIs. The rest stays on the server, so the bundle is smaller.
4. How does caching work in Next.js?
Results of fetch and pages can be cached and revalidated by time or tag. Behavior is configured with fetch options and revalidation functions.
Interview questions from the bank
- How do Server Components differ from Client Components?MiddleReact
- What are the core App Router concepts in Next.js: layout, page, loading, error?MiddleReact
- How do Actions for forms work in React 19, and which hooks go with them?MiddleReact
- What is hydration, and why does a hydration mismatch happen?MiddleReact
- What are Core Web Vitals, and which metrics do they include?JuniorFrontend performance
- What causes CLS, and how do you avoid it?JuniorFrontend performance
- How do you load images correctly so they do not slow the page?JuniorFrontend performance
- How do you improve LCP?MiddleFrontend performance
Comparisons with this technology
Related technologies
- ReactA library for building interfaces from components: UI as a function of state.
- NuxtA full-stack Vue framework: SSR, file-based routing, auto-imports and the Nitro server engine.
- AstroA framework for content sites: ships minimal JavaScript by default, with interactive islands on demand.
- VercelA frontend platform from the creators of Next.js: Git deploys, a preview for every PR, serverless functions and edge.
- TypeScriptA superset of JavaScript with static types that compiles to plain JS.
Logos belong to their owners and are used for identification only. Icons: Simple Icons (CC0), Devicon (MIT).