0
0
Astroframework~8 mins

client:load directive in Astro - Performance & Optimization

Choose your learning style9 modes available
Performance: client:load directive
MEDIUM IMPACT
This affects the page's initial load speed by deferring JavaScript execution until after the page is fully loaded.
Loading interactive components without blocking initial page render
Astro
<MyComponent client:load />
Executes JavaScript right after page load, improving interactivity timing without blocking initial render.
📈 Performance GainImproves LCP and reduces INP compared to client:idle
Loading interactive components without blocking initial page render
Astro
<MyComponent client:idle />
Delays loading until browser is idle, which can postpone interactivity and increase input delay.
📉 Performance CostMay increase INP by delaying script execution beyond page load
Performance Comparison
PatternDOM OperationsReflowsPaint CostVerdict
client:loadMinimal extra DOM nodesTriggers 1 reflow after loadPaint cost delayed but minimal[OK] Good
client:idleMinimal extra DOM nodesReflows delayed until idlePaint cost delayed, may cause input lag[!] OK
client:visibleMinimal extra DOM nodesReflows triggered on visibilityPaint cost depends on scroll[!] OK
Static (no directive)Minimal extra DOM nodesNo reflows from JSNo additional paint cost[✓] Best
Rendering Pipeline
The client:load directive defers JavaScript execution until after the page's load event, allowing the browser to prioritize HTML and CSS rendering first.
HTML Parsing
Style Calculation
Layout
Paint
JavaScript Execution
⚠️ BottleneckJavaScript Execution stage can delay interactivity if scripts run too early or too late.
Core Web Vital Affected
LCP
This affects the page's initial load speed by deferring JavaScript execution until after the page is fully loaded.
Optimization Tips
1Use client:load to run scripts immediately after page load for balanced performance.
2Avoid eager loading scripts that block initial rendering to improve LCP.
3client:load improves interactivity timing compared to client:idle by running scripts sooner.
Performance Quiz - 3 Questions
Test your performance knowledge
What is the main benefit of using the client:load directive in Astro?
AIt delays JavaScript execution until after the page load event to improve initial render speed.
BIt runs JavaScript immediately during HTML parsing to speed up interactivity.
CIt delays JavaScript execution until the user scrolls the component into view.
DIt runs JavaScript only when the browser is idle.
DevTools: Performance
How to check: Record a performance profile during page load, then look for the timing of script execution and main thread activity after the load event.
What to look for: Scripts running immediately after load event with minimal blocking indicate good client:load usage.