Performance: client:visible for viewport-based loading
This pattern affects page load speed by deferring component loading until it enters the viewport, improving initial load and interaction readiness.
import MyWidget from './MyWidget.astro'; <MyWidget client:visible />
import MyWidget from './MyWidget.astro'; <MyWidget client:load />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Immediate hydration | High (all components loaded) | Multiple reflows during hydration | High paint cost due to JS execution | [X] Bad |
| client:visible hydration | Low (only visible components) | Single reflow per visible component | Lower paint cost, deferred JS | [OK] Good |
client:visible directive do in Astro?client:visibleclient:visible to load components on visibility.client:visible correctly in JSX-like syntax.<Image src="photo.jpg" alt="Photo" client:visible />
<Video src="movie.mp4" client-visible />
client:visible is correct, not client-visible.src attribute is present, and self-closing slash is optional in JSX-like syntax.client:visible. Which approach best improves performance without hurting user experience?client:visible only to widgets below the fold, load above-the-fold normally. balances performance and experience; others either delay too much or avoid optimization.Pass the test and this pattern moves unknown