0
0
NextJSframework~8 mins

Layout vs template difference in NextJS - Performance Comparison

Choose your learning style9 modes available
Performance: Layout vs template difference
MEDIUM IMPACT
This concept affects how quickly the main page content loads and how efficiently the browser updates the UI when navigating between pages.
Sharing common UI parts across multiple pages
NextJS
export default function Layout({ children }) {
  return (
    <>
      <header>Site Header</header>
      <main>{children}</main>
      <footer>Site Footer</footer>
    </>
  )
}

// Pages use Layout to wrap content, so header/footer render once.
Layout keeps shared UI stable, so only main content changes on navigation, reducing reflows.
📈 Performance GainSingle reflow for main content changes, improving LCP and reducing CPU work.
Sharing common UI parts across multiple pages
NextJS
export default function Page() {
  return (
    <>
      <header>Site Header</header>
      <main>Page content</main>
      <footer>Site Footer</footer>
    </>
  )
}
Repeats header and footer on every page causing full re-render and slower load on navigation.
📉 Performance CostTriggers full reflow and repaint on every page load, increasing LCP.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Template with repeated header/footerHigh (full page nodes recreated)Multiple reflows per navigationHigh paint cost due to full repaint[X] Bad
Layout with shared header/footerLow (shared nodes reused)Single reflow for content updateLower paint cost focused on content[OK] Good
Rendering Pipeline
Layouts keep shared UI elements stable in the DOM, so only the main content updates during navigation. Templates that repeat full page structure cause the browser to recalculate styles and layout for all elements each time.
Style Calculation
Layout
Paint
⚠️ BottleneckLayout stage is most expensive when full page structure changes repeatedly.
Core Web Vital Affected
LCP
This concept affects how quickly the main page content loads and how efficiently the browser updates the UI when navigating between pages.
Optimization Tips
1Use layouts to keep shared UI stable across pages.
2Avoid repeating full page structure in every page component.
3Reducing DOM changes lowers layout recalculations and speeds up LCP.
Performance Quiz - 3 Questions
Test your performance knowledge
Which pattern reduces layout recalculations when navigating pages in Next.js?
ARepeating header and footer in every page component
BLoading all page content in one big template
CUsing a layout component to wrap shared UI
DUsing inline styles for every element
DevTools: Performance
How to check: Record a page navigation in DevTools Performance panel. Look at the Layout and Paint events to see how much work is done.
What to look for: Less Layout and Paint time means better performance. Repeated full page reflows indicate template pattern; minimal reflows indicate layout usage.