Performance: When to hydrate vs keep static
This concept affects page load speed and interaction responsiveness by deciding when JavaScript activates on the page.
import MyWidget from './MyWidget.astro'; <MyWidget client:idle />
import MyWidget from './MyWidget.astro'; <MyWidget client:load />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Hydrate entire page immediately | High (many nodes hydrated) | Multiple reflows | High paint cost due to JS | [X] Bad |
| Hydrate interactive widgets on idle | Moderate (only widgets) | Single reflow | Lower paint cost | [OK] Good |
| Keep static content without hydration | Low (static DOM) | No reflows from JS | Minimal paint cost | [OK] Good |
client:load to hydrate a component immediately after the page loads.client:load hydrates on load, client:idle waits for idle, client:visible hydrates when visible, and no directive means no hydration.<Counter client:idle />
client:idle directive delays hydration until the browser is idle, improving performance.<Button client:load>Click</Button>
client:load only work on Astro components, not plain HTML elements.client:load on a native HTML tag like <Button> (instead of a component) does nothing, so no interactivity.client:visible delays hydration until visible, improving load speed. Keeping news feed static avoids unnecessary hydration.Pass the test and this pattern moves unknown