Astro Island Architecture: What It Is and How It Works
Astro Island Architecture is a way to build web pages where most content is static HTML, but small interactive parts called islands load JavaScript only when needed. This approach keeps pages fast by sending minimal JavaScript and activating interactivity only on specific components.How It Works
Imagine a web page as a big island with many small islands scattered around it. The big island is the static HTML that loads quickly and shows content immediately. The small islands are interactive parts like buttons, forms, or maps that need JavaScript to work.
Astro Island Architecture sends the static HTML first, so users see the page fast. Then, only the small interactive islands load their JavaScript separately and become active. This way, the page stays lightweight and fast, but still has rich interactivity where needed.
This is like reading a newspaper where most pages are printed text and pictures, but some pages have pop-up features that you open only if you want to interact with them.
Example
This example shows an Astro page with a static heading and an interactive counter island that loads JavaScript only for the button.
--- import Counter from '../components/Counter.jsx'; --- <html lang="en"> <head> <title>Astro Island Example</title> </head> <body> <h1>Welcome to Astro Island Architecture</h1> <Counter client:load /> </body> </html>
When to Use
Use Astro Island Architecture when you want fast-loading pages with some interactive parts. It is perfect for blogs, marketing sites, or documentation where most content is static but you need small interactive widgets like forms, counters, or maps.
This approach reduces the amount of JavaScript sent to the browser, improving performance and user experience, especially on slow networks or devices.
Key Points
- Static HTML loads first for fast page display.
- Interactive islands load JavaScript only when needed.
- Improves performance by reducing JavaScript sent to the browser.
- Great for sites with mostly static content and some interactive widgets.