The client:load directive tells Astro to load and run a component only after the page has fully loaded in the browser. This helps keep the initial page fast and interactive.
client:load directive in Astro
<ComponentName client:load />
Use it as an attribute on your Astro or framework component.
This directive delays loading the component's JavaScript until after the browser finishes loading the page.
MyWidget only after the page load event.<MyWidget client:load />
Counter component will hydrate and run after the page is fully loaded.<Counter client:load />
This Astro page imports a Counter component and uses client:load to load it only after the page finishes loading. The heading appears immediately, and the counter becomes interactive after load.
--- import Counter from '../components/Counter.jsx'; --- <html lang="en"> <head> <title>Client Load Example</title> </head> <body> <h1>Welcome to Astro</h1> <Counter client:load /> </body> </html>
The client:load directive is great for non-critical interactive parts.
It waits for the full page load event, so it may delay interactivity slightly.
Use it to balance speed and interactivity in your Astro projects.
client:load delays component loading until after the page fully loads.
It helps keep initial page load fast and adds interactivity later.
Use it for widgets or components that don't need to run immediately.
Practice
client:load directive do in Astro?Solution
Step 1: Understand the purpose of
This directive delays the component's loading until after the full page load event.client:loadStep 2: Compare with other loading strategies
Unlike immediate or lazy loading on visibility,client:loadwaits for the whole page to finish loading.Final Answer:
It delays loading a component until the entire page has loaded. -> Option AQuick Check:
client:loaddelays loading = A [OK]
- Confusing client:load with immediate loading
- Thinking it loads on scroll or visibility
- Assuming it prevents client loading entirely
client:load on a component named MyWidget?Solution
Step 1: Recall Astro directive syntax
Astro directives use colon syntax likeclient:loadas an attribute on components.Step 2: Check valid self-closing tag usage
Using<MyWidget client:load />is valid and concise for components without children.Final Answer:
<MyWidget client:load /> -> Option DQuick Check:
Correct directive syntax = A [OK]
- Replacing colon with camelCase or dash
- Omitting the colon
- Using incorrect closing tags
<MyWidget client:load />
What will happen when the page loads?
Solution
Step 1: Understand client:load behavior
Theclient:loaddirective delays loading the component until after the full page load event in the browser.Step 2: Compare with other loading triggers
It does not load immediately or on scroll, but waits for the page to fully load.Final Answer:
MyWidget loads only after the entire page finishes loading in the browser. -> Option CQuick Check:
client:load triggers after full page load = D [OK]
- Thinking it loads during server rendering
- Confusing with lazy loading on scroll
- Assuming it never loads on client
<MyWidget client-load />
What is the error?
Solution
Step 1: Identify incorrect directive syntax
The directive uses a dashclient-loadinstead of the required colonclient:load.Step 2: Understand Astro directive rules
Astro directives must use colon syntax exactly; dashes are invalid and ignored.Final Answer:
The directive should beclient:loadwith a colon, not a dash. -> Option BQuick Check:
Correct directive syntax uses colon = C [OK]
- Using dash instead of colon in directive
- Thinking directives need imports
- Believing self-closing tags cause loading issues
Solution
Step 1: Identify the requirement
The chat widget should load only after the full page load to keep initial load fast.Step 2: Match directive to requirement
client:loaddelays loading until after the page fully loads, fitting the need perfectly.Step 3: Compare other options
client:idlewaits for browser idle,client:visiblewaits for scroll visibility, and no directive loads immediately.Final Answer:
Use <ChatWidget client:load /> to delay loading until after page load. -> Option AQuick Check:
Delay until full page load = client:load = B [OK]
- Choosing client:idle or client:visible which load at different times
- Not using any directive causing immediate load
- Misunderstanding when client:load triggers
Ready to prove it?
Pass the test and this pattern moves unknown
