Difference between next.js new and old architecture
This document compares the old architecture of Next.js (before version 13) with the new App Router-based architecture introduced in Next.js 13+. It highlights the key differences in routing, data fetching, layout handling, hydration, and more — in simple terms.
1. Routing System
Old Architecture (pages/)
- Routing is based on the /pages folder.
- Each file becomes a route.
- Example:
/pages/about.js → /about
/pages/blog/[slug].js → /blog/my-post
New Architecture (app/)
- Routing is now based on the /app folder.
- You use page.js inside each route folder.
- Example:
/app/about/page.js → /about
/app/blog/[slug]/page.js → /blog/my-post
2. Layouts
Old Architecture
- One global layout: _app.js and _document.js.
- Hard to create unique layouts for different routes.
New Architecture
- Supports nested layouts.
- Each route can have its own layout.js.
- Example:
/app/about/layout.js → Layout for the about page
/app/blog/layout.js → Layout for all blog pages
3. Static Site Generation (SSG)
Old Architecture
- Uses:
- getStaticProps() → fetch data at build time.
- getStaticPaths() → generate paths for dynamic routes.
New Architecture
- Uses:
- generateStaticParams() → replaces getStaticPaths().
- fetch() directly in Server Components → replaces getStaticProps().
Example:
// Old
export async function getStaticProps() { ... }
export async function getStaticPaths() { ... }
// New
export async function generateStaticParams() { ... }
const data = await fetch(...); // inside server component
4. Server-Side Rendering (SSR)
Old Architecture
- Uses getServerSideProps() to fetch data on every request.
- Adds latency for each user request.
New Architecture
- SSR is automatic using React Server Components.
- Just use fetch() directly in the component.
- Pages are cached after the first load.
Revalidation Options:
- revalidate: 60 → Automatically regenerate every 60 seconds.
- On-Demand Revalidation → Trigger regeneration manually via API when content updates (great for blogs).
5. Hydration
Old Architecture
- All pages were fully hydrated on the client.
- HTML is sent first, then JavaScript is downloaded to make it interactive.
- Even static parts (like headers) had JavaScript overhead.
New Architecture
- Only Client Components ("use client") are hydrated.
- Server Components do not require hydration or JS on the client.
- Reduces JS bundle size → faster performance.