The 60-second version
Short on time? Here is the whole guide as a tweet-sized thread. Copy one, or copy all.
The Big Picture
Ten steps from โI wrote codeโ to โThe page works when I click.โ Tap each step on the left.
Remember from this chapter
- Next.js is a pipeline, not one magic box โ each step has a clear job.
- Most data work stays on the server; the browser gets HTML first, JS only where needed.
- Production output lives in .next after
next build.
Route Discovery
Folder names on your computer become website addresses (URLs).
about, the website gets an /about door. Next.js walks your app/ folder like a librarian with a map.File tree โ click a file
Generated route manifest
Route mapping
Folder names become URL segments. page.tsx marks a routable page. Dynamic segments use [param].
The actual screen for a URL
Wrapper shared by pages in that folder
Spinner while the page prepares
Organize files without changing the URL
Remember from this chapter
- No central routes file โ the folder tree is the map.
- Special filenames (
layout,loading,error) add behavior aroundpage.
Dependency Graph
Pages use pieces (components). Pieces can use smaller pieces. Thatโs a โwho needs whoโ map.
Dependencies
Click a module in the graph.
Remember from this chapter
- Every
importis an edge in the graph โ the bundler walks it from each page. - Shared imports become shared chunks; duplicate heavy deps inflate download size.
SWC Compiler
Browsers donโt speak JSX. SWC translates your code super fast.
Compiler pipeline โ click to animate
Remember from this chapter
- SWC replaces slower JS-based compilers for most Next.js transforms.
- Dev = readable code; production = minified output in
.next.
React Server Components
Some work happens on a big computer far away โ not in your pocket phone browser.
Gets the finished poster (HTML)
Cooks the page
async function Page() {
const posts = await db.posts.findMany()
return <PostList posts={posts} />
}
๐ซ Server Component
- Cooks in the kitchen (server)
- Can ask the library (database)
- Doesnโt add weight to your backpack (no extra JS)
๐ฎ Client Component
- Runs on your device
- Clicks, typing, animations
- Ships JavaScript in the download
Remember from this chapter
- Default in App Router: components are Server Components unless you say otherwise.
- Server code can use secrets and databases; it never ships as source to the client.
Client Components
Interactive bits (clicks, typing) need JavaScript downloaded to the browser.
"use client" means โthis part needs buttons that work on your device.โ More client parts = bigger download (heavier backpack).Estimated bundle
0 KB
Toggle client components below
Remember from this chapter
- Put
"use client"only on components that need browser APIs, state, or effects. - Client boundaries pull in JavaScript cost โ keep them small and low in the tree when possible.
React Flight
The server sends recipe cards, not the whole kitchen.
Component tree
Page โ Hero โ Sidebar โ Dashboard
Payload inspector
M1:{"id":"./Hero","chunks":["M2"]}
M2:["$","section",null,{"children":"..."}]
Remember from this chapter
- Flight is Reactโs wire format for Server Components โ a stream of instructions, not TSX source.
- The client reconciler builds UI from Flight + existing client component modules.
Bundling
Pack JavaScript into suitcases (chunks) so visitors download only what they need.
Remember from this chapter
- Code splitting = many small files instead of one giant download.
- Shared UI (header/footer) should land in a shared chunk cached across routes.
Webpack vs Turbopack
When you change one file, how much does the tool rebuild?
Webpack
Often rebuilds the whole neighborhood
โ ms
Turbopack
Mostly rebuilds the one house you touched
โ ms
Simulated dev rebuild after editing one file. Real times vary by project size.
Remember from this chapter
- Turbopack (dev) targets incremental rebuilds; Webpack remains common in production tooling history.
- Fast feedback loops matter as much as production bundle size.
Build Output
After next build, Next.js leaves a .next folder โ the packed lunch for production.
Select a folder or file
Remember from this chapter
- Never edit
.nextby hand โ it is regenerated bynext dev/next build. - Manifests tell the runtime where routes and assets live in production.
Request Lifecycle
What happens when someone visits your site โ step by step.
Request flow
Click a node to see details.
Remember from this chapter
- One page view can touch CDN, server, database, and client โ know which step you are debugging.
- Streaming lets users see HTML before all data finishes loading.
Hydration Simulator
The page looks ready before buttons truly work.
The button is only a picture right now โ try clicking it!
Remember from this chapter
- Hydration mismatch errors mean server HTML and client render disagree โ fix the diff, donโt ignore warnings.
- Only Client Components need hydration for interactivity.
Cache System
Remember answers so you donโt ask the library the same question every second.
Remembers whole pages that donโt change often
Donโt ask the same API twice in one cook session
Keeps resized photos ready nearby
Old page stays fast while a fresh one bakes behind the scenes
Remember from this chapter
- Caching is a tradeoff: speed vs freshness โ configure
revalidateandfetchoptions on purpose. - โStale dataโ bugs often mean cache rules, not React bugs.
Build Your Own Next.js
Next.js is really six jobs. Match each job to its slot.
Remember from this chapter
- Frameworks combine routing, compile, bundle, run, render, and cache โ Next.js packages opinions for React apps.
- You could swap pieces (e.g. different bundler) but you inherit integration cost.
Final Summary
You made it! Hereโs the whole story in one breath.
๐ Folders = URLs
Put pages in the right folder and the address appears by magic (convention).
๐ซ Server does heavy lifting
Fetch data on the server; send HTML first, JavaScript only for interactive toys.
โ๏ธ Flight = recipe cards
Instructions cross the wire โ not your whole secret codebase.
๐ Cache = memory
Save answers so the next visitor gets a speedy reply.
You can explain Next.js to anyone now
- Start with folders โ end with hydration and cache.
- When stuck, ask: is this build time, request time, or browser time?
Middleware
Code that runs before a page, for matching URLs only.
export function middleware(req) {
if (!req.cookies.has('session') && req.nextUrl.pathname.startsWith('/dashboard'))
return NextResponse.redirect(new URL('/login', req.url))
if (req.nextUrl.pathname === '/old-blog')
return NextResponse.rewrite(new URL('/blog', req.url))
return NextResponse.next()
}
export const config = { matcher: ['/((?!api|_next).*)'] }
Remember from this chapter
- Middleware runs before routing finishes โ keep it fast and small.
- Use
config.matcherso it skips assets and API paths. - Redirect changes the URL; rewrite keeps the URL but serves another page. Newer Next.js versions rename this file convention to
proxyโ check your version.
Server Actions
Submit a form and run a function on the server โ no hand-written API route.
async function addTodo(formData) {
'use server'
await db.todos.create({ title: formData.get('title') })
revalidatePath('/todos')
}
Remember from this chapter
- A Server Action is a public POST endpoint โ always validate input and check auth inside it.
revalidatePath/revalidateTagtell Next.js which cached data is now stale.- Forms can work before hydration โ progressive enhancement.
Streaming & Suspense
Send the page in pieces so slow parts never block fast parts.
<Suspense> is a covered plate.<Header />
<Suspense fallback={<Skeleton />}><Reviews /></Suspense>
<Suspense fallback={<Skeleton />}><Recommendations /></Suspense>
Without streaming the user would see nothing until the slowest part finishes.
Remember from this chapter
- Streaming improves perceived speed: users see the shell immediately.
loading.tsxis automatic Suspense around a whole route segment.- Put Suspense close to the slow data, not around the whole page.
Rendering Strategies
SSG, SSR, ISR, PPR โ pick by who sees the page and how often it changes.
HTML built at next build. Fastest, CDN friendly.
HTML built per request. Fresh and personal, costs server time.
Static page re-generated after revalidate time or on demand.
Static shell plus streamed dynamic holes. Availability depends on version.
Remember from this chapter
- Using cookies, headers or uncached data makes a route dynamic automatically.
- Static is cheaper and faster; dynamic is fresher and personal.
- You choose per route, not per app.
Node vs Edge Runtime
Where your server code runs decides which tools it can use.
export const runtime = 'edge' // or 'nodejs'
Remember from this chapter
- Edge = fast cold start, low latency, limited Node APIs.
- Native modules,
fsand many DB drivers need the Node runtime. - Choose per route with
export const runtime; default to Node unless you have a reason.
Glossary
Search terms you hear in Next.js docs โ each with a simple line and a precise line.
Do I need Node to read this page?
No. Double-click the HTML file. Everything runs in your browser.
Is this official Next.js documentation?
No. It is a community education artifact. Always confirm behavior with the docs for your Next.js version.
Why one HTML file?
So you can fork, ship, and teach without npm, CI, or hosting lock-in. Perfect for README demos and workshops.
What license?
MIT โ use commercially, modify, redistribute. Keep the license notice in the file header when you redistribute.