Skip to content

Start

Introduction

ogygia adds islands to SvelteKit, so a page ships as server HTML without Kit's client and only the components you mark load JavaScript. This page explains the idea and maps every feature to its page.

On this page

Most pages in a SvelteKit app are content with a few interactive parts: a cart button, a search box, a menu. Kit still sends its whole client to the browser and hydrates the entire component tree, so a page that needs JavaScript for one widget pays for all of it.

ogygia is an islands architecture for SvelteKit that removes that cost. You turn off Kit’s client for a route, and the page ships as plain server HTML. Then you mark the imports that should be interactive, and only those components load JavaScript, when the page needs them. It runs on stock SvelteKit and Svelte, with no patches to either.

The heading ships no JavaScript. Cart renders on the server like any component, and its code loads only when it scrolls into view. The counter below is a real island on this page, marked wake: 'load', and the text around it is static HTML:

A live island
10

Everything else on this page is static HTML.

<script>
  import Cart from '$lib/Cart.svelte' with {
    wake: 'visible'
  };
</script>

<h1>Everything here is static HTML.</h1>
<Cart />

Use cases

ogygia fits pages that are mostly content with small interactive parts: marketing pages, docs, blogs, storefronts, dashboards built from tiles. If a page is one large interactive application, a normal Kit page with csr = true is the simpler tool.

You don’t have to choose for the whole app. ogygia works route by route, so a content route can drop Kit’s client while an app-like route next to it keeps it. Install shows how to adopt it one route at a time.

What you keep:

  • Ordinary Svelte. An island is a normal component. The import attribute is the only new syntax.
  • SvelteKit. Server loads, form actions and remote functions work as usual, and islands read page.data.
  • Server HTML first. Every region starts as HTML from the server. What every region promises says how each kind does it.

How it works

A normal Kit page starts the Kit client, which hydrates the whole tree. With csr = false, Kit sends no client at all, and the page is only HTML.

ogygia puts a small runtime in its place: a custom element, <ogygia-region>, which wraps each marked component in the server HTML. The runtime’s boot script is 25.4 KB brotli-compressed with the SPA router, which is on by default, and 20.1 KB with ogygia({ router: false }). That’s the script every page loads, without Svelte or your islands’ own code. The code that hydrates an island (about 3 KB more) loads at the first wake.

Features add their code only when your app uses them. With the router off, an app with server islands boots 29.3 KB, one with lakes 26.6 KB, and one with live regions (held regions that query.live sends) 30.0 KB. These numbers are the SPA router, Static content, Deferred regions, Frozen regions and Live regions profiles of pnpm bundle-size, and Performance has the rest.

When an island’s moment comes, the runtime loads that island’s code and hydrates it in place, against the HTML that is already there. Nothing else on the page runs.

In the example, the root layout turns Kit’s client off for every route and places a search box that wakes on the first interaction.

export const csr = false;
<script>
  import Search from '$lib/Search.svelte' with {
    wake: 'interaction'
  };
  let { children } = $props();
</script>

<header><Search /></header>
{@render children()}

Region kinds

Every marked import becomes a region: a part of the page with its own rule for where its HTML comes from and when its JavaScript runs. You pick the rule with import attributes, or with region() for a held region. There are four kinds:

  • a client island (wake) hydrates on a schedule;
  • a server island (render: 'deferred') is a hole the server fills after the page loads;
  • a lake (wake: 'none') is static HTML inside an island;
  • a held region (region()) is a component the server picks at runtime.

Children and snippets passed into an island cross as regions too.

Regions compares them side by side, and Timing and nesting covers the schedules. The example places three: a menu that wakes at once, a greeting the server fills after the page loads, and a chart that wakes when it scrolls into view.

<script>
  import Menu from '$lib/Menu.svelte' with { wake: 'load' };
  import Greeting from '$lib/Greeting.svelte' with {
    render: 'deferred'
  };
  import Chart from '$lib/Chart.svelte' with {
    wake: 'visible'
  };
</script>

<Menu />
<Greeting />
<Chart />

Features

The docs have one section per package. The switcher at the top of the sidebar moves between them. This section covers ogygia, the package every app installs.

Regions (ogygia):

  • Client islands: mark an import, ship its JavaScript on a schedule. Includes boot islands, which run code with no UI.
  • Server islands: holes filled from a signed endpoint, with fallbacks, caching, requestEvent() and keepFallback().
  • Lakes: static HTML inside an island, and site chrome that stays static on csr = true pages.
  • Held regions: region() and <Region>, for search results, feeds and server-driven UI.
  • Live regions: live regions over query.live, repaints from a command’s answer, and a header that refreshes.
  • Snippets: children and snippets passed into an island, and region.snippet().
  • Timing and nesting: every schedule, the click replay, how downloads are queued, and the rule for regions inside regions.
  • DOM ownership: where a web component or a third-party widget can sit inside an island.

The app (ogygia):

  • SPA router: client navigation with no Kit client, prefetch, view transitions, kept layout chrome, lifecycle events and partial prerendering.
  • Dashboards: a recipe for tiles as islands sharing one filter object.
  • Web components: web components that paint before their JavaScript loads.

Data and state (ogygia):

  • Remote functions: Kit’s query, command and form inside islands.
  • State and context: one live object shared by many islands, context that reaches into islands, and state that survives navigation.
  • Page data: page.data inside islands, and streamed promises.
  • Serialization: what crosses into an island, and import.meta.og.$ for functions.

Build-time macros (ogygia):

Other packages, each installed on its own (see Packages):

Reference:

Next steps

Read these in order. Each builds on the one before.

  1. Install: add the package, the Vite plugin and the server handle.
  2. Quickstart: build a static page with one island, then add a server island.
  3. Packages: what else you can install. Skim it, and come back when you need a feature.
  4. Regions: the one idea behind every kind of region.
  5. Client islands: what you’ll write most.