Astro islands: hydrate only what needs it

Most of a page is static. Islands ship JavaScript for the interactive parts only, and you choose when it loads.

A content page rarely needs JavaScript beyond a few widgets: a search box, a theme switch, a code playground. Islands render everything to HTML and hydrate only those widgets.

Pick the directive

Each island says when its code loads. The lighter the directive, the less work on the main thread at startup.

<Search client:idle />
<Comments client:visible />
<Playground client:only="preact" />
  • client:idle waits until the browser is idle.
  • client:visible waits until the element scrolls into view.
  • client:only skips server rendering; use it only when the component cannot render on the server.

Share state without a library

Two islands that need the same state can import the same signal from a small module. Each island hydrates on its own, and the signal keeps them in sync.