Skip to main content
Server Islands allow you to embed dynamic, server-rendered components within static pages. This gives you the best of both worlds: fast static page loads with selective server-rendered content for personalization, real-time data, or authentication.

What are Server Islands?

Server Islands are components that render on the server for each request, even when the rest of the page is statically generated. They load asynchronously after the initial page render, providing dynamic content without blocking the main page load.
Server Islands require an SSR adapter and work in output: 'static' or output: 'hybrid' modes.

Creating a Server Island

Mark any component as a server island using the server:defer directive:
src/pages/index.astro

Server Island Component

Server islands are just regular Astro components that can access server-side features:
src/components/UserProfile.astro

How It Works

1

Initial Page Load

The static HTML is served immediately with a placeholder for the server island.
2

Server Rendering

The browser requests the server island content via a background fetch:
3

Hydration

The server responds with rendered HTML, which replaces the placeholder:
  • Initial page loads instantly (static HTML)
  • Server islands load asynchronously
  • No blocking on server-rendered content
  • Main content visible immediately
Provide fallback content that shows while loading:

Use Cases

Personalization

Show user-specific content like profiles, recommendations, or preferences

Real-time Data

Display live data like stock prices, availability, or analytics

Authentication

Render auth-protected content based on session state

A/B Testing

Serve different variants for experiments

Passing Props

Pass props to server islands just like regular components:
src/pages/product/[id].astro
src/components/StockStatus.astro
Props are encrypted during transmission for security. Don’t pass sensitive data that shouldn’t be cached.

Slots

Use slots to pass content to server islands:
src/pages/dashboard.astro
src/components/AdminPanel.astro

Configuration

Enable server islands in your Astro config:
astro.config.mjs
Server islands work best with output: 'hybrid' for mixing static and dynamic content.

Combining with Client Islands

Mix server islands with client-side framework components:
src/pages/app.astro
  • Render on server for each request
  • Access databases and sessions
  • Load asynchronously
  • No JavaScript hydration needed
  • Render on client
  • Interactive components
  • Require JavaScript
  • Hydrate in the browser

Caching Strategies

Control caching for server islands:
src/components/CachedWidget.astro
Use with server:defer:

Error Handling

Handle errors gracefully in server islands:
src/components/WeatherWidget.astro

Loading States

Provide meaningful loading states:
src/pages/index.astro

Advanced Example

A complete example combining multiple concepts:
src/pages/dashboard.astro

Best Practices

1

Keep islands small

Server islands should be focused components. Split large components into multiple islands.
2

Provide fallbacks

Always show something while loading. Use skeleton screens or loading messages.
3

Handle errors

Gracefully handle failures and provide retry mechanisms.
4

Consider caching

Cache server island responses when appropriate to reduce server load.
5

Monitor performance

Track server island response times and optimize slow queries.

SSR and SSG

Understanding rendering modes

Components

Building Astro components

Islands Architecture

Learn about islands architecture

Middleware

Add server-side logic