Bird
Raised Fist0
Astroframework~10 mins

client:visible for viewport-based loading in Astro - Interactive Code Practice

Choose your learning style10 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to load the component only when it becomes visible in the viewport.

Astro
<MyComponent [1] />
Drag options to blanks, or click blank then click option'
Aclient:media
Bclient:visible
Cclient:idle
Dclient:load
Attempts:
3 left
💡 Hint
Common Mistakes
Using client:load loads immediately, not on visibility.
client:idle waits for idle time, not visibility.
client:media loads based on media queries, not viewport visibility.
2fill in blank
medium

Complete the code to import and use a component with viewport-based loading.

Astro
---
import MyComponent from './MyComponent.astro';
---

<div>
  <[1] [2] />
</div>
Drag options to blanks, or click blank then click option'
Aclient:load
Bclient:visible
CMyComponent
DMyComponentVisible
Attempts:
3 left
💡 Hint
Common Mistakes
Using the directive name as the component tag.
Using an undefined component name.
3fill in blank
hard

Fix the error in the component usage to enable viewport-based loading.

Astro
<MyComponent [1] />
Drag options to blanks, or click blank then click option'
Aclient:only
Bclient:load
Cclient:idle
Dclient:visible
Attempts:
3 left
💡 Hint
Common Mistakes
Using client:load loads immediately, not on visibility.
client:idle waits for idle time, not visibility.
client:only is not a valid directive.
4fill in blank
hard

Fill both blanks to create a component that loads only when visible and passes a prop.

Astro
<[1] [2] someProp="value" />
Drag options to blanks, or click blank then click option'
AMyComponent
Bclient:visible
Cclient:load
DOtherComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the component name and directive.
Using client:load instead of client:visible.
5fill in blank
hard

Fill all three blanks to import a component, use viewport-based loading, and pass a prop.

Astro
---
import [1] from './[2].astro';
---

<[3] client:visible message="Hello" />
Drag options to blanks, or click blank then click option'
AMyComponent
DOtherComponent
Attempts:
3 left
💡 Hint
Common Mistakes
Mismatching import name and filename.
Using a different component name in the tag.

Practice

(1/5)
1. What does the client:visible directive do in Astro?
easy
A. It loads a component only when it appears in the user's viewport.
B. It loads a component immediately when the page loads.
C. It prevents a component from ever loading.
D. It loads a component only on server side.

Solution

  1. Step 1: Understand the purpose of client:visible

    This directive delays loading until the component is visible on screen, saving resources.
  2. Step 2: Compare options with this behavior

    Only It loads a component only when it appears in the user's viewport. matches this behavior; others describe immediate or no loading.
  3. Final Answer:

    It loads a component only when it appears in the user's viewport. -> Option A
  4. Quick Check:

    client:visible = loads on viewport [OK]
Hint: Remember: client:visible means load when visible on screen [OK]
Common Mistakes:
  • Thinking it loads immediately on page load
  • Confusing with server-side loading
  • Assuming it never loads the component
2. Which of the following is the correct syntax to load a component only when visible using Astro?
easy
A.
B.
C.
D.

Solution

  1. Step 1: Recall Astro client directives

    Astro uses client:visible to load components on visibility.
  2. Step 2: Match syntax with directive

    Only uses client:visible correctly in JSX-like syntax.
  3. Final Answer:

    <Component client:visible /> -> Option B
  4. Quick Check:

    Correct directive syntax = [OK]
Hint: Use client:visible exactly as attribute on component [OK]
Common Mistakes:
  • Using client:load instead of client:visible
  • Confusing with client:idle or client:only
  • Missing the colon in client:visible
3. Given this Astro code snippet, what will happen when the page loads?
<Image src="photo.jpg" alt="Photo" client:visible />
medium
A. The image never loads.
B. The image loads immediately when the page loads.
C. The image loads only when it scrolls into the viewport.
D. The image loads only after a user clicks it.

Solution

  1. Step 1: Understand client:visible effect on image

    The image will not load immediately but waits until visible on screen.
  2. Step 2: Analyze options for loading behavior

    The image loads only when it scrolls into the viewport. correctly states loading on scroll into viewport; others are incorrect.
  3. Final Answer:

    The image loads only when it scrolls into the viewport. -> Option C
  4. Quick Check:

    client:visible delays load until visible [OK]
Hint: client:visible delays loading until visible on screen [OK]
Common Mistakes:
  • Assuming image loads immediately
  • Thinking it loads on click
  • Believing it never loads
4. Identify the error in this Astro component usage:
<Video src="movie.mp4" client-visible />
medium
A. The src attribute is missing.
B. The directive client-visible is correct syntax.
C. The component tag should be self-closing with a slash at the end.
D. The directive should be client:visible with a colon, not a dash.

Solution

  1. Step 1: Check directive syntax

    Astro directives use colon, so client:visible is correct, not client-visible.
  2. Step 2: Verify other attributes and syntax

    The src attribute is present, and self-closing slash is optional in JSX-like syntax.
  3. Final Answer:

    The directive should be client:visible with a colon, not a dash. -> Option D
  4. Quick Check:

    Directive syntax requires colon, not dash [OK]
Hint: Use colon in client:visible, not dash [OK]
Common Mistakes:
  • Using dash instead of colon in directive
  • Thinking self-closing slash is mandatory
  • Missing src attribute (which is present here)
5. You want to optimize a page with many interactive widgets using client:visible. Which approach best improves performance without hurting user experience?
hard
A. Apply client:visible only to widgets below the fold, load above-the-fold normally.
B. Apply client:visible to all widgets, including those visible on initial load.
C. Avoid using client:visible and load all widgets immediately.
D. Use client:visible only on images, not interactive widgets.

Solution

  1. Step 1: Consider user experience for above-the-fold content

    Widgets visible immediately should load right away for smooth interaction.
  2. Step 2: Use client:visible for below-the-fold widgets

    Delaying load for widgets off-screen saves data and speeds initial load.
  3. Step 3: Evaluate options

    Apply 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.
  4. Final Answer:

    Apply client:visible only to widgets below the fold, load above-the-fold normally. -> Option A
  5. Quick Check:

    Optimize below fold with client:visible, load above fold immediately [OK]
Hint: Use client:visible only for off-screen widgets to keep UX smooth [OK]
Common Mistakes:
  • Applying client:visible to all widgets including visible ones
  • Not using client:visible at all
  • Limiting client:visible only to images
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard