Hydrating adds interactivity to parts of your webpage. Keeping static means the content stays simple and fast without extra scripts.
When to hydrate vs keep static in Astro
Astro component with hydration directive: --- import MyComponent from './MyComponent.jsx'; --- <MyComponent client:load /> Static Astro content: --- --- <h1>Hello, world!</h1>
The client:load directive tells Astro to hydrate the component when the page loads.
Static content in Astro does not include any hydration directives and stays simple HTML.
--- import InteractiveButton from './InteractiveButton.jsx'; --- <InteractiveButton client:load />
--- --- <p>This is static text that does not change or respond to user actions.</p>
--- import Form from './Form.jsx'; --- <Form client:idle />
--- import Widget from './Widget.jsx'; --- <Widget client:visible />
This Astro page shows a static title and a counter component that becomes interactive after loading.
--- import Counter from './Counter.jsx'; --- <h1>Static Title</h1> <Counter client:load />
Hydrating too many components can slow down your page load time.
Use static content whenever possible for faster and simpler pages.
Astro offers different hydration strategies like client:load, client:idle, and client:visible to optimize performance.
Hydrate components only when you need interactivity.
Keep content static if it does not require user actions.
Choose hydration strategies wisely to balance speed and functionality.
Practice
Solution
Step 1: Understand static components
Static components do not need to respond to user actions or update dynamically.Step 2: Identify when to keep static
If a component only shows fixed information without interactivity, it should remain static for better performance.Final Answer:
When the component only displays information and has no user interaction -> Option AQuick Check:
Static = no interactivity [OK]
- Thinking all components must hydrate
- Hydrating components without user actions
- Confusing static with dynamic updates
Solution
Step 1: Recall hydration directives
Astro usesclient:loadto hydrate a component immediately after the page loads.Step 2: Match syntax to behavior
client:loadhydrates on load,client:idlewaits for idle,client:visiblehydrates when visible, and no directive means no hydration.Final Answer:
<MyComponent client:load /> -> Option DQuick Check:
client:load = hydrate on load [OK]
- Using client:idle when immediate hydration is needed
- Omitting hydration directive expecting auto hydration
- Confusing client:visible with client:load
<Counter client:idle />
What happens when the page loads?
Solution
Step 1: Understand client:idle behavior
Theclient:idledirective delays hydration until the browser is idle, improving performance.Step 2: Predict component behavior on load
On page load, the component is static until the browser has free time, then it hydrates and becomes interactive.Final Answer:
The Counter component hydrates only when the browser is idle -> Option CQuick Check:
client:idle = hydrate on idle [OK]
- Assuming immediate hydration with client:idle
- Thinking client:idle means no hydration
- Confusing client:idle with client:visible
<Button client:load>Click</Button>
But the button is not interactive. What is the likely problem?
Solution
Step 1: Check hydration on static elements
Hydration directives likeclient:loadonly work on Astro components, not plain HTML elements.Step 2: Identify the problem in code
Usingclient:loadon a native HTML tag like<Button>(instead of a component) does nothing, so no interactivity.Final Answer:
You used client:load on a static HTML element -> Option BQuick Check:
Hydrate only Astro components, not plain HTML [OK]
- Assuming hydration works on native HTML tags
- Not importing components correctly
- Confusing client:load with client:visible
Solution
Step 1: Analyze component interactivity needs
The live chat requires interactivity, so it needs hydration. The news feed is static content and does not need hydration.Step 2: Choose hydration strategy for performance
Hydrating chat withclient:visibledelays hydration until visible, improving load speed. Keeping news feed static avoids unnecessary hydration.Final Answer:
Keep news feed static and hydrate chat with client:visible -> Option AQuick Check:
Hydrate interactive only, keep static content static [OK]
- Hydrating static content unnecessarily
- Delaying hydration of interactive parts too long
- Hydrating everything immediately hurting performance
Ready to prove it?
Pass the test and this pattern moves unknown
