Start
Quickstart
Build a static page with one interactive island and one server island, from an empty route to a working page in about five minutes.
On this page
This is the shortest path to a working page: plain server HTML, one island that hydrates, and one server island that fills in after the page loads. You need a SvelteKit app. If you don’t have one, npx sv create my-app makes one.
1. Add ogygia
If you already followed Install, skip to step 2. Otherwise, run init in your app’s folder. It installs the package, adds the Vite plugin and the server handle, and writes the two hook files. Install explains each change, if you’d rather make them by hand.
npx ogygia initpnpm dlx ogygia init2. Turn off Kit’s client
To try it, set csr = false in one section’s +layout.ts. Now no route in that section ships Kit’s client, and each of its pages is plain server HTML until you mark something. The rest of your app stays as it is.
In a new app with nothing to keep, you can put it in the root +layout.ts instead and cover every route. In an existing app, move one route at a time, as Install explains.
export const csr = false;<script>
let { start = 0 } = $props();
let count = $state(start);
</script>
<button onclick={() => (count += 1)}>count is {count}</button>4. Mark the import
Add with { wake: 'load' } to the import. That attribute is the whole opt-in: Counter becomes an island, and everything else on the page stays static HTML.
Props work as usual, as long as they are data the server can serialize. A function can’t be a prop, because it can’t travel to the browser. Pass data into an island lists what crosses.
<script>
import Counter from '$lib/Counter.svelte' with {
wake: 'load'
};
</script>
<h1>A static page</h1>
<p>This heading and text ship no JavaScript.</p>
<Counter start={3} />5. Run it and look
Start the dev server with npm run dev and open /demo. The button counts. The widget below is a real island on this page, marked wake: 'load' the same way. Its time stamp is written by an $effect, so it shows the moment the island woke:
Open the page source. The heading and paragraph are plain HTML. The button’s HTML is there too, wrapped in an <ogygia-region> element, which is how the runtime finds the island. Turn JavaScript off and reload: the page looks the same, and only the button stops counting.
6. Change when it wakes
The word you give wake decides when the island’s JavaScript loads and runs. Change it and nothing else about the page changes. Try wake: 'interaction': the counter now loads no JavaScript until you hover, focus or click it, and that click still counts.
The other words are 'idle', 'visible' and a media query. Timing and nesting explains each one.
<script>
import Counter from '$lib/Counter.svelte' with {
wake: 'interaction'
};
</script>
<h1>A static page</h1>
<p>This heading and text ship no JavaScript.</p>
<Counter start={3} />7. Add a server island
Some parts depend on who is asking but don’t need to be interactive, like a greeting. Mark that import render: 'deferred' and it becomes a server island: the page ships with a fallback, and the browser fetches the real HTML from the server after the page loads. It ships no JavaScript.
requestEvent() gives the server island the request it renders for, so it can read locals or cookies. Fallback types the ogygiaFallback snippet you pass at the call site. Server islands covers both.
<script lang="ts">
import { requestEvent, type Fallback } from 'ogygia';
import type { RequestEvent } from '@sveltejs/kit';
let { site }: Fallback<{ site: string }> = $props();
const name =
requestEvent<RequestEvent>()?.cookies.get('name') ??
'friend';
</script>
<p>Welcome to {site}, {name}.</p><script>
import Counter from '$lib/Counter.svelte' with {
wake: 'interaction'
};
import Greeting from '$lib/Greeting.svelte' with {
render: 'deferred'
};
</script>
<Counter start={3} />
<Greeting site="my app">
{#snippet ogygiaFallback()}<p>Welcome.</p>{/snippet}
</Greeting>Where to go next
- Regions: the one idea behind islands, server islands, lakes and held regions.
- Client islands: what props can carry, boot islands, and named imports from a package.
- Data and remote functions: give an island a server to talk to.
- SPA router: page changes with no reload, already on.