Start
Installation
Add the package, the Vite plugin and the server handle once, with one command or by hand. Then move routes to islands one at a time while the rest of your Kit pages keep working as they are.
On this page
ogygia installs into an existing SvelteKit app. You add a few pieces once: the package, the Vite plugin, the server handle and two small hook files. Nothing changes on any page until you turn off Kit’s client for a route and mark its islands, so you can adopt it one route at a time.
You need SvelteKit 2.70.2 or later, or Kit 3; Svelte 5.56.8 or a later 5.x; and Vite 8.2.4 or a later 8.x.
Automatic setup
ogygia init does the whole setup in the app in the current folder:
npx ogygia initpnpm dlx ogygia initIt makes these changes, and merges into what you already have instead of overwriting it:
package.json: addsogygiatodependenciesand@ogygia/clitodevDependencies, so laternpx ogygiacommands run your local copy.vite.config.ts: addsogygia()beforesveltekit().src/hooks.server.ts: addsogygia.handle(). If you already export ahandle, it puts both in asequence().src/hooks.ts: adds thetransporthook. If you already export atransport, it spreads ogygia’s into it.src/ogygia.d.ts: adds the type reference, in TypeScript projects only..gitignore: adds**/.ogygia-keep-client/, a folder the build makes for a moment and removes (see An app with no Kit client at all).
It asks whether to add markdown content collections. With markdown on, it also adds @ogygia/content and edits svelte.config.js, as Add markdown content shows. --markdown or --no-markdown answers up front, -y accepts the defaults, and --no-install skips the package install. It does not set csr = false on any route; you do that when you’re ready. The CLI’s commands page lists every command.
The sections below show each piece, for when you’d rather add them by hand or want to know what init wrote.
Manual install
ogygia depends on @ogygia/core and @ogygia/compiler; core brings in @ogygia/machine. Every other feature is a separate package, listed on Packages.
npm i ogygiapnpm add ogygiaVite plugin
List ogygia() before sveltekit(). The plugin rewrites marked imports before Svelte compiles them, so it has to see the source first. It also sets enforce: 'pre', and listing it after sveltekit() fails the build (plugin_after_sveltekit).
The plugin adds @ogygia/core’s folder, where the runtime lives, to Vite’s server.fs.allow, so in a monorepo Vite serves the runtime from outside your app. Every option is on API and config, and an option ogygia() doesn’t have fails the build (option_unknown).
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [ogygia(), sveltekit()]
});Server handle
ogygia.handle() serves the signed endpoint that server islands and live lakes fetch their HTML from, and adds the data islands need to the page. Without it, server islands never fill. So server islands, live lakes and held regions the browser fetches later need a running server: a fully static adapter-static build has nothing to answer them.
The endpoint’s default path is /__ogygia__. To move it, pass endpoint. The path sits under Kit’s paths.base, so write it without the base. Pick a path your deployment actually sends to the app: behind a proxy that forwards only some prefixes, put it under one of them. Don’t put it under Kit’s appDir (/_app/…), because Kit answers those paths before any handle runs.
If you have other handles, combine them with sequence(). Packages shows the order when other ogygia packages add handles too.
import * as ogygia from 'ogygia/server';
export const handle = ogygia.handle();import { sequence } from '@sveltejs/kit/hooks';
import * as ogygia from 'ogygia/server';
import { auth } from '$lib/server/auth';
export const handle = sequence(
auth,
ogygia.handle({ endpoint: '/_server/api/__ogygia__' })
);Transport hook
A held region can travel from a remote function or a server load to the browser. Kit sends values of custom types from the server to the browser through the transport hook in src/hooks.ts (the universal hooks file, not the server one). Add ogygia’s codecs (the code that turns a region into text and back) to it.
An app that never sends a region to the browser this way doesn’t need it. Adding it anyway is safe, because the build only includes the codecs your app uses. If you already have a transport of your own, spread ogygia’s into it: { ...ogygia.transport, ...yours }.
import * as ogygia from 'ogygia';
export const transport = ogygia.transport;Types
The plugin provides build-time modules (ogygia:*) and the import.meta.og macros. Your editor and svelte-check need one reference line to see their types. Without it, svelte-check reports those imports as unresolved, although the build works.
/// <reference types="ogygia/types" />Incremental adoption
To convert a route, turn off Kit’s client for it and mark its islands. csr cascades like any Kit page option, so set it in a +layout.ts to cover a whole section, or in one +page.ts. Every other route stays a normal Kit page.
Start with your most static, highest-traffic route, where removing the client gains the most. Then go route by route and measure. Quickstart walks through the first island.
On a csr = false page, the page’s own <script> never runs in the browser, so browser code goes in an island (boot islands). Constraints lists the other rules.
export const csr = false;Kit pages
A route that is one big interactive app can stay csr = true. The two kinds of route live side by side:
- Navigation. ogygia’s SPA router is on for the whole app, with no component to place. On a
csr = trueroute Kit’s client owns navigation, and ogygia leaves its clicks alone. To turn the router off everywhere, useogygia({ router: false }). - Marked imports on a Kit page. Kit hydrates the whole page, islands included, so a
wakeschedule does nothing there (in dev, ogygia says so once:island_on_kit_page). The mark still helps with loading, because a marked component’s code loads only when the server rendered it. Acsr = trueroute that imports a registry of a hundred marked blocks loads the code and CSS of the blocks on the page, not of all hundred. - Lakes and holes on a Kit page. A lake is adopted as it is, and ships none of its code. Server islands and islands inside a lake still run on ogygia’s runtime.
- Shared code.
isOgygiaPage()fromogygiatells a store or a helper which kind of page it runs on, on the server and in the browser. Call it inside a function, never at module top level: on the server a module runs once and is shared by every request, so a top-level answer belongs to no page.
import { isOgygiaPage } from 'ogygia';
export function saveTheme(theme: string) {
// Kit pages keep the theme in localStorage; ogygia pages send it to the server
if (!isOgygiaPage())
localStorage.setItem('theme', theme);
else document.cookie = `theme=${theme}; path=/`;
}Islands-only apps
You can set csr = false in the root +layout.ts and remove Kit’s client everywhere. When every route has csr = false, Kit normally skips its client build, which would also drop your island chunks. During the build, ogygia adds a hidden route with no URL so Kit still builds its client, and removes it afterwards. You don’t need a placeholder csr = true route.
export const csr = false;Markdown (optional)
For .md and .svx content collections, add @ogygia/content and list its content() plugin beside ogygia(). npx ogygia init --markdown does this for you. The @ogygia/content section covers the package.
Put extensions and preprocess in svelte.config.js, not inline on sveltekit(), and keep the rest of your config (your adapter, say) as it is. Kit, svelte-check and the Svelte language server all read svelte.config.js, and options passed inline hide it from them. extensions() adds .svx and .md only while markdown is on, and preprocess() loads mdsvex on first use.
The content macros (import.meta.og.loader, og.code, og.md) have their own types, so add a second line to src/ogygia.d.ts.
npm i @ogygia/contentpnpm add @ogygia/contentimport { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { content } from '@ogygia/content/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [ogygia(), content({ markdown: {} }), sveltekit()]
});import adapter from '@sveltejs/adapter-auto';
import { vitePreprocess } from '@sveltejs/vite-plugin-svelte';
import { preprocess, extensions } from '@ogygia/content/vite';
export default {
extensions: extensions(),
preprocess: [vitePreprocess(), ...preprocess()],
kit: { adapter: adapter() }
};/// <reference types="ogygia/types" />
/// <reference types="@ogygia/content/types" />Other features
Flags, images, the server router, postrender, federation, devtools and the rest are separate packages. Each one is installed on its own and listed once in plugins, after ogygia() and before sveltekit(). Some also add a line to hooks.server.ts. Packages lists them all, with their plugins and where each is documented.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { flags } from '@ogygia/flags/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [ogygia(), flags(), sveltekit()]
});Environment variables
Before you deploy, check these:
OGYGIA_SECRET: the key that signs server-island URLs, at least 16 bytes. A shorter one fails the production build (secret_too_short), or the handle, when you pass it assecret(handle_secret_too_short). Set it on every deployment. Without it, each build signs with its own random key, so a page cached across a deploy, or served by one server while another answers its endpoint, gets its holes refused (secret_missing). Prerendered pages with server islands need it.ORIGIN(adapter-node, or any server behind a proxy that rewrites the host): commands, remote functions and form POSTs go through Kit’s origin check, which compares the request’s origin with the one your server believes it has. Without the rightORIGIN, Kit rejects them with403. Other adapters get the origin from the platform.
If your server can’t read its environment at run time, pass the secret to the handle instead. OGYGIA_SECRET has the details.
import { OGYGIA_SECRET } from '$env/static/private';
import * as ogygia from 'ogygia/server';
export const handle = ogygia.handle({ secret: OGYGIA_SECRET });Do and don’t
- Do start with your most static, highest-traffic route.
- Do list
ogygia()beforesveltekit(). - Do keep app-like routes on
csr = true. ogygia works alongside them. - Don’t set the whole of an existing app to
csr = falseon day one. Convert route by route and measure. - Don’t add a placeholder
csr = truepage to keep an all-islands build alive. It isn’t needed. - Don’t forget
OGYGIA_SECRETin production, orORIGINon adapter-node.