0
0
NextJSframework~8 mins

Use client directive in NextJS - Performance & Optimization

Choose your learning style9 modes available
Performance: Use client directive
MEDIUM IMPACT
This affects how components are rendered and hydrated on the client, impacting initial load speed and interactivity.
Rendering a component that does not need client-side interactivity
NextJS
export default function StaticComponent() {
  return <div>Hello, static content!</div>;
}
Renders the component as a server component, sending only HTML to the client, reducing bundle size and speeding up LCP.
📈 Performance GainSaves 10-30kb of JavaScript, reduces blocking time, improves LCP and INP.
Rendering a component that does not need client-side interactivity
NextJS
"use client";

export default function StaticComponent() {
  return <div>Hello, static content!</div>;
}
Forces the component to be bundled and hydrated on the client even though it is static, increasing JavaScript size and delaying LCP.
📉 Performance CostAdds unnecessary JavaScript to bundle, blocking rendering and increasing LCP by 100-200ms depending on device.
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
Server component (no "use client")Minimal, static HTML0Low[OK] Good
Client component with "use client"Hydrated with JS event handlers1-2Medium[!] OK
Unnecessary "use client" on static componentHydrated unnecessarily1-3High[X] Bad
Rendering Pipeline
The client directive controls whether a component is rendered on the server or hydrated on the client. Server components send HTML only, while client components add JavaScript for hydration and interactivity.
Server Rendering
JavaScript Bundling
Hydration
Interaction
⚠️ BottleneckHydration stage is most expensive when client directive is overused, causing large JS bundles and slower interactivity.
Core Web Vital Affected
LCP, INP
This affects how components are rendered and hydrated on the client, impacting initial load speed and interactivity.
Optimization Tips
1Use "use client" only on components that need client-side interactivity.
2Avoid adding "use client" to static components to reduce JavaScript bundle size.
3Check hydration performance in DevTools to find unnecessary client directives.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main performance cost of adding "use client" to a static component?
AReduces server rendering speed
BCauses layout shifts during page load
CIncreases JavaScript bundle size and delays initial content rendering
DImproves interaction speed
DevTools: Performance
How to check: Record a performance profile during page load and interaction. Look for long scripting tasks related to hydration and large JS bundles.
What to look for: High scripting time and large JS files indicate overuse of client directive causing slower LCP and INP.