What if your page could feel instantly fast by smartly waiting to run code?
Why client:idle for deferred hydration in Astro? - Purpose & Use Cases
Imagine loading a webpage with many interactive parts, and you try to make each part ready to use immediately by running all JavaScript as soon as the page loads.
This can make the page feel slow and heavy, especially on slower devices or connections.
Running all JavaScript right away uses a lot of the browser's power at once, causing delays and making the page less responsive.
It also wastes resources on parts the user might never interact with, leading to a poor experience.
The client:idle directive tells the browser to wait until it is idle before running JavaScript to make components interactive.
This spreads out the work, making the page load faster and feel smoother.
<MyComponent client:load />
<MyComponent client:idle />
This lets your website load quickly and stay responsive by deferring less urgent JavaScript until the browser has free time.
On a news site, the main article loads immediately, but interactive comment sections only become active when the browser is idle, so the reader can start reading without delay.
Loading all JavaScript immediately can slow down your page.
client:idle defers JavaScript until the browser is free, improving speed.
This creates smoother, faster user experiences by prioritizing important content.