0
0
NextJSframework~8 mins

Why layouts avoid redundant rendering in NextJS - Performance Evidence

Choose your learning style9 modes available
Performance: Why layouts avoid redundant rendering
HIGH IMPACT
This concept affects page load speed and interaction responsiveness by reducing unnecessary re-rendering of shared UI parts.
Rendering shared UI elements across multiple pages
NextJS
function Layout({ children }) {
  return (
    <>
      <header>Site Header</header>
      <main>{children}</main>
      <footer>Site Footer</footer>
    </>
  )
}

export default function Page() {
  return <Layout>Page Content</Layout>
}
The header and footer render once in the layout and do not re-render on page changes, reducing redundant work.
📈 Performance GainShared UI renders once, cutting re-render time by up to 50% and improving interaction responsiveness (INP).
Rendering shared UI elements across multiple pages
NextJS
export default function Page() {
  return (
    <>
      <header>Site Header</header>
      <main>Page Content</main>
      <footer>Site Footer</footer>
    </>
  )
}
The header and footer re-render every time the page changes, causing redundant work and slower interactions.
📉 Performance CostTriggers full re-render of shared UI on every navigation, increasing CPU usage and blocking rendering for tens of milliseconds.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
No layout, repeated UI in pagesHigh (header/footer recreated each page)Multiple reflows per navigationHigh paint cost due to full UI repaint[X] Bad
Shared layout wrapping pagesLow (header/footer mounted once)Single reflow on initial loadLower paint cost, only main content repainted[OK] Good
Rendering Pipeline
Layouts keep shared UI components mounted across page navigations, so the browser skips recalculating styles and layouts for those parts repeatedly.
Style Calculation
Layout
Paint
⚠️ BottleneckLayout stage is most expensive due to recalculating positions and sizes of all DOM nodes.
Core Web Vital Affected
INP
This concept affects page load speed and interaction responsiveness by reducing unnecessary re-rendering of shared UI parts.
Optimization Tips
1Use layouts to keep shared UI mounted and stable across pages.
2Avoid duplicating header/footer in every page component to reduce reflows.
3Check DevTools Performance panel for repeated layout and paint events on shared UI.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance benefit of using layouts in Next.js?
AAvoids re-rendering shared UI on every page navigation
BReduces JavaScript bundle size by removing code
CImproves SEO by adding meta tags automatically
DEnables server-side rendering for all pages
DevTools: Performance
How to check: Record a page navigation in the Performance panel and look for repeated style, layout, and paint events on shared UI elements.
What to look for: Fewer layout and paint events on header/footer indicate good layout usage avoiding redundant rendering.