Discover how to make your website lightning fast by smartly choosing when to add JavaScript!
When to hydrate vs keep static in Astro - When to Use Which
Imagine building a website where every interactive button and form needs JavaScript to work. You try adding scripts manually to each part, but it quickly becomes a mess to manage and slows down your page.
Manually adding JavaScript to every element means loading lots of code even when users don't need it. This makes pages slow to load and can confuse browsers, causing bugs and poor user experience.
Astro lets you choose when to add JavaScript to your components: hydrate them only when needed for interactivity, or keep them static if they don't require scripts. This keeps pages fast and smooth.
Add scripts to every component regardless of need, causing slow load times.
<Component client:load /> to hydrate only interactive parts, <Component /> to keep static parts without extra scripts.
This choice lets you build fast websites that only use JavaScript where it truly matters, improving speed and user experience.
A blog page where static articles load instantly, and only the comment form hydrates JavaScript when a user wants to interact.
Manually adding JavaScript everywhere slows down pages.
Hydration means adding scripts only to interactive parts.
Keeping components static saves resources and speeds up loading.