0
0
Astroframework~5 mins

client:media for responsive interactivity in Astro - Cheat Sheet & Quick Revision

Choose your learning style9 modes available
Recall & Review
beginner
What is client:media in Astro Framework?

client:media is a directive in Astro that loads a component only when a specific media query matches, enabling responsive interactivity.

Click to reveal answer
beginner
How does client:media improve website performance?

It delays loading interactive components until the user's device matches the media query, reducing unnecessary JavaScript and speeding up initial load.

Click to reveal answer
beginner
Write an example of using client:media to load a component only on screens wider than 768px.
<MyComponent client:media="(min-width: 768px)" />
Click to reveal answer
intermediate
What happens if the media query in client:media does not match?

The component does not load or run its JavaScript, so it stays static or is not rendered interactively.

Click to reveal answer
intermediate
Can client:media be used with multiple media queries?

Yes, you can use any valid CSS media query string, including combined queries like (min-width: 600px) and (orientation: landscape).

Click to reveal answer
What does client:media="(max-width: 600px)" do in Astro?
ALoads the component only on screens wider than 600px
BLoads the component only on screens 600px wide or smaller
CLoads the component on all screen sizes
DPrevents the component from loading on any screen
Which benefit does client:media provide?
ADelays loading components until media query matches
BImproves SEO by hiding components
CAutomatically styles components based on screen size
DPreloads all components regardless of screen size
If a component uses client:media="(min-width: 1024px)", when will it load?
AOnly on screens narrower than 1024px
BNever loads
COnly on screens 1024px wide or wider
DOn all screen sizes
Can client:media be used to load components based on device orientation?
ANo, it only works with width and height
BOnly on mobile devices
COnly on desktop devices
DYes, it supports any valid CSS media query
What happens if the media query changes after the page loads?
AThe component automatically loads or unloads accordingly
BThe component loads only once and does not react to changes
CThe page reloads automatically
DThe component crashes
Explain how client:media helps create responsive interactive components in Astro.
Think about when and why components load depending on screen size or device features.
You got /4 concepts.
    Describe a real-life scenario where using client:media would improve user experience.
    Consider how different devices or screen sizes might need different interactive parts.
    You got /4 concepts.