Astro Islands & SSR (50 Qs)•Part 3: Advanced Internals, Scale & Production Architecture (Senior / Lead)
Astro Client Directives: `client:load`, `client:idle`, `client:visible`, `client:media`, and `client:only`.
senior LevelCode ExampleDirectivesCLISystem Design
In Simple Words: By default, Astro renders all UI components (React, Vue, Svelte) to pure, zero-JavaScript HTML at build/server time. Client Directives selectively tell Astro when to send JavaScript to hydrate an Island in the browser:
client:load: High-priority; hydrates immediately when page finishes loading (navigation bars, critical search inputs).client:idle: Low-priority; hydrates once the browser's main thread is idle (requestIdleCallback).client:visible: Hydrates only when the element scrolls into the user's viewport (IntersectionObserver), perfect for footers, comments, and below-the-fold carousels.client:media="(max-width: 768px)": Hydrates only if a CSS media query matches.client:only="react": Skips server rendering completely and renders solely on the client.
astro
<!-- Hydration Directives in Astro -->
<Header client:load />
<ProductFilter client:idle />
<CustomerReviews client:visible />
<MobileNav client:media="(max-width: 640px)" />