Performance: client:media for responsive interactivity
This affects how quickly interactive components respond to viewport changes and user input on different screen sizes.
<MyComponent client:media="(min-width: 768px)" /><MyComponent client:load />
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| client:load on all screens | High (all scripts loaded) | Multiple reflows if scripts modify DOM | High paint cost due to unnecessary event listeners | [X] Bad |
| client:media with media query | Low (scripts loaded conditionally) | Single reflow when media matches | Lower paint cost, fewer event listeners | [OK] Good |
client:media in Astro components?client:media doesclient:media loads components conditionally based on media queries, meaning it only activates when the screen matches certain conditions.client:media?(min-width: 768px).<MyWidget client:media="(max-width: 600px)" />
(max-width: 600px) matches screen widths 600px or less.<Sidebar client:media="min-width: 1024px" />
(min-width: 1024px).client:media attribute correctly achieves this?and to combine (min-width: 600px) and (max-width: 1200px). Options A and B have reversed or impossible ranges. <NavigationMenu client:media="(min-width: 600px) or (max-width: 1200px)" /> uses or, which matches too broadly.Pass the test and this pattern moves unknown