What Next.js is and how it works
Next.js is a React framework for websites and web applications. On top of React components it adds file-based routing, rendering on the server and at build time, caching and the Turbopack bundler. The browser receives a page as ready-made HTML, and data is loaded on the server.
Choose Next.js when a fast first load, search visibility and data access without a separate API matter: a Server Component reads the database directly, and only the JavaScript for interactive parts is sent to the browser. Plain React with just a bundler is the choice when no framework fits your project’s constraints or when you are learning the basics of React.
Next.js has two routers. The App Router uses the app/ directory, was introduced in version 13 and is built on React Server Components; the older Pages Router uses the pages/ directory. This reference describes the App Router, which create-next-app recommends and sets up.
The path of a request
The core of Next.js is that a page is rendered on the server, and the browser receives HTML for a fast first paint plus the RSC payload, a compact description of the component tree that React uses to build the interface. JavaScript is loaded only for Client Components, and later navigations within the app happen without a full page reload.
- The browser requests a URL, for example
/blog/hello. - If the project has a
proxy.ts, it runs first and can redirect the request, rewrite the URL or add headers. - Next.js matches the route from the folders in
app/and renders its layouts and page on the server. Server Components read data straight from the database or an API. - The server responds with HTML and the RSC payload, a serialised tree of Server Components with placeholders for Client Components.
- The browser shows the HTML immediately, and React performs hydration: it attaches event handlers to the existing markup.
- When you follow a
<Link>, the browser requests only the RSC payload of the new route from the server, without HTML; often it has already been prefetched. - React updates the page in place: shared layouts and their state are preserved.
Static and dynamic
In Next.js the line between static and dynamic runs through components, not routes. A single page can consist of a static shell that is ready at build time and served immediately, cached parts with their own lifetime, and dynamic parts that are streamed in at request time. So “static site or server-rendered” is not a choice for the whole project: the decision is made per component.
How it differs from React with a bundler
| What you need | React and Vite | Next.js |
|---|---|---|
| Routing | a separate library, such as React Router | folders in app/ |
| Rendering | in the browser: a single-page application (SPA) | on the server and at build time; the browser receives ready-made HTML |
| Data fetching | in the browser, with libraries such as TanStack Query or SWR | in Server Components, straight from the database or an API |
| Server Components, SSR and SSG | you have to build it yourself | built in |
| Caching | in the data-fetching library | 'use cache', lifetimes and tags |
| Bundler | Vite | Turbopack, built in |
Choose Next.js if you need server-generated HTML, server-side data fetching and routing out of the box. React with Vite fits when the app lives entirely in the browser and you are ready to assemble routing and data fetching yourself.
What to know beforehand
- JavaScript and TypeScript: modules, promises,
async/await(see the JavaScript and TypeScript references) - React: components, props, state, hooks (see the React reference)
- The Server Components model and the
'use client'and'use server'directives (see the React reference, section “Server Components and Server Functions”) - HTTP: methods, status codes, headers, cookies (see the HTTP and REST reference)
Section sources
the section is written from these pages- Next.js Rendering Philosophynextjs.org/docs/app/guides/rendering-philosophy(opens in a new tab)
- Server and Client Componentsnextjs.org/docs/app/getting-started/server-and-client-components(opens in a new tab)
- Next.js Glossarynextjs.org/docs/app/glossary(opens in a new tab)
- Project structure and organizationnextjs.org/docs/app/getting-started/project-structure(opens in a new tab)
- Build a React app from Scratchreact.dev/learn/build-a-react-app-from-scratch(opens in a new tab)