0
0
NextJSframework~8 mins

App directory (App Router) in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: App directory (App Router)
MEDIUM IMPACT
This affects the page load speed and rendering performance by how Next.js organizes and loads routes and components.
Organizing routes and components for faster page loads
NextJS
app/
  page.js
  about/page.js
  contact/page.js
  layout.js
  components/
    Header.js
    Footer.js

// Components and routes are loaded per route automatically
Next.js automatically code splits by route and loads only needed components, reducing initial bundle size.
📈 Performance GainReduces initial JS bundle by 30-50%, improving LCP by 100-200ms
Organizing routes and components for faster page loads
NextJS
pages/
  index.js
  about.js
  contact.js
components/
  Header.js
  Footer.js

// All components imported globally in _app.js
All components and routes are bundled together, causing larger initial JavaScript payload and slower first paint.
📉 Performance CostBlocks rendering for 200-300ms longer on initial load due to large bundle size
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Pages directory with global importsHigh (all components loaded)Multiple reflows due to large JSHigh paint cost from large DOM[X] Bad
App directory with route-based code splittingLow (only route components)Single reflow per routeLower paint cost with smaller DOM[OK] Good
Rendering Pipeline
The App Router organizes routes as folders with page and layout files. On navigation, only the relevant route components are fetched and rendered, reducing work in style calculation, layout, and paint.
JavaScript Parsing
Style Calculation
Layout
Paint
⚠️ BottleneckJavaScript Parsing and Execution due to large bundles
Core Web Vital Affected
LCP
This affects the page load speed and rendering performance by how Next.js organizes and loads routes and components.
Optimization Tips
1Use the App directory to enable automatic route-based code splitting.
2Avoid importing all components globally to reduce initial bundle size.
3Leverage server components in the App Router to minimize client JavaScript.
Performance Quiz - 3 Questions
Test your performance knowledge
How does using the Next.js App directory improve page load performance?
ABy bundling all components into one large file for faster caching
BBy automatically code splitting routes and loading only needed components
CBy disabling JavaScript on the client side
DBy preloading all images on the homepage
DevTools: Performance
How to check: Record page load and navigation in Performance tab. Look at JS parsing and scripting times and size of loaded scripts.
What to look for: Lower JS execution time and smaller script sizes indicate better App Router usage.