Brian Adams Headshot
Back to All Posts

Islands in the Sun

Experiments in Astro Islands

Tuesday, March 12, 2024
An island with palms on a sunny day

One of the coolest features of Astro is that you can use many of the most popular UI libraries to build components. These components will be rendered either statically for static generated sites (like this one), or on the server side for server side rendered sites.

Astro also embraces a concept called Islands, which was popularized by Katie Sylor-Miller. By default, components in Astro are only rendered server side, and only the resulting HTML/CSS is sent down to the server. This means that unless you specify otherwise, components won’t include any of their JavaScript when loaded client side. This means that for components that don’t have interactivity, end users aren’t penalized with larger payloads, and they don’t have to spend extra time waiting for the browser to parse JavaScript needlessly.

For the times when a component does have interactivity, you can add a client directive to instruct Astro to include the JavaScript. This creates islands of interactive components, and since it’s opt-in, pages only incur extra costs when absolutely necessary. Even better, non-critical components can use directives like client:visible to have the component only hydrated client side if it comes into view (this can be especially useful for components deep in an article or in a footer, since users may never get to them).

This post has a small test component I wrote in Vue, and then converted to other UI libraries with the help of ChatGPT. The data visible in each component is the same array of items defined just once, and passed down into each component.

View This Post’s Code

Test Component (Vue)

First NameLast Name
BrianAdams
JohnDoe
JaneDoe

View Vue Component Code

Test Component (React)

First NameLast Name
BrianAdams
JohnDoe
JaneDoe

View React Component Code

View Lit Component Code

Test Component (Preact)

First NameLast Name
BrianAdams
JohnDoe
JaneDoe

View Preact Component Code

Test Component (Solid)

First NameLast Name
BrianAdams
JohnDoe
JaneDoe

View Solid Component Code

Test Component (Svelte)

First Name Last Name
Brian Adams
John Doe
Jane Doe

View Svelte Component Code

Test Component (Alpine.js)

First Name Last Name

View Alpine Component Code