Reference
API map
Every public import path of ogygia and its packages, what each one holds, its generated API page and the guide that explains it. Also the import attributes, every option of the ogygia() Vite plugin, and the build helper plugins.
On this page
- Import map
- ogygia
- Run code before the first paint with script()
- Save a visitor’s choice with preference()
- Import attributes
- ogygia/vite
- visible
- presets
- router
- ttl
- maxPageAge
- rateLimit
- sessionCookie
- importKeys
- OGYGIA_SECRET
- ogygia/server
- ogygia/app
- ogygia/events
- Build helper plugins
- dataShake()
- barrels()
- bake()
- image()
- jumpstart()
This page tells you where things are. Find the import path you have, or the one you need, and it points you at two pages: the generated API page, built from the package’s own type declarations, with every signature and option; and the guide, which explains when and why to use it.
It also holds the reference that has no other home: the full list of ogygia exports, script() and preference(), the import attributes, the options of ogygia(), and the build helper plugins.
Import map
The ogygia package’s import paths. ogygia re-exports @ogygia/core and @ogygia/compiler (ogygia/vite is @ogygia/compiler/vite), so an app imports from ogygia only.
| Import path | What’s in it | API page | Guide |
|---|---|---|---|
ogygia | Components and functions you use in pages and islands. The list. | ogygia | Regions |
ogygia/vite | ogygia(), the Vite plugin, and definePlugin(). | ogygia/vite | Options below |
ogygia/server (also ogygia/hooks) | handle(), document() and the server transport. | ogygia/server | Install |
ogygia/app | goto, invalidateAll and the rest of $app/navigation, safe inside islands. | ogygia/app | SPA router |
ogygia/events | The event layer: add_sink, snapshot, clear and the event types. | ogygia/events | The event stream |
ogygia/types | Ambient types: the virtual modules and import.meta.og.wire, $, source. | none | Add the types |
ogygia/plugin, /plugin/client, /plugin/utils, /plugin/css, /plugin/testing | The plugin API, for writing a package like the ones below. Not stable for outside authors. | plugin, client, utils, css, testing | Plugins |
ogygia/runtime, ogygia/internal/* | Used by code ogygia generates. Don’t import them. | ogygia/runtime | none |
Each other package has its own import paths. Install the package, then import from it.
| Import path | What’s in it | API page | Guide |
|---|---|---|---|
@ogygia/content, /server, /markdown, /vite, /docs-shell, /slot, /types, CSS | content(), the loaders, blocks(), site(), withRemotes(), the markdown pipeline, the docs shell. | content, server, markdown, vite | Entry points & config |
@ogygia/image, /vite, /Img.svelte, /types | Img, getImage, isImage, remoteImage; the plugin image() with sharp(), cloudflare(), vercel(). | image, vite | Image |
@ogygia/router, /api, /vite | routes, page, layout, load, action, the verbs, when, redirect, error, fail; the typed api() client. | router, api | Server router |
@ogygia/postrender, /vite | postrender and its stores (MemoryStore, ValkeyStore, …) and CDN edges (AkamaiEdge, …). | postrender | Postrender |
@ogygia/flags, /openfeature, /vite | flag, decide; openfeature, ofrep; flags. | flags, openfeature, vite | Feature flags |
@ogygia/federation, /shared, /vite | federate, mount, user; SharedState. | federation, shared, vite | Federation |
@ogygia/devtools, /vite, /report, /profiler, /profiler/client, /profiler/storage, /profiler/storage/{sqlite,redis,postgres} | The dock and profiler plugin, profiler reports, span and instrument, mark, report stores. | devtools, report, profiler, client, storage | Devtools |
@ogygia/testing, /vite | withOgygia, Ogygia, the matchers, compare; testing. | testing, vite | Testing |
@ogygia/rewrite, /vite | rewrite(), a Kit handle for your own pass over the HTML. | rewrite, vite | Rewrite |
@ogygia/insights | The analysis behind the dock, the profiler and @ogygia/testing, for your own tools. | insights | Measure your own app |
@ogygia/data-shake/vite | dataShake(). | vite | Datashake |
@ogygia/bake, /types | bake(), the plugin behind import.meta.og.bake. | bake | Bake |
@ogygia/barrels | barrels(). | barrels | Barrels |
@ogygia/jumpstart | jumpstart(). | jumpstart | Jumpstart |
@ogygia/tsdown-plugin-svelte | svelte(), a tsdown plugin for component libraries. Nothing in an app imports it. | tsdown-plugin-svelte | Overview |
@ogygia/cli | The ogygia command. Nothing to import. | none | Commands |
@ogygia/machine, /testing | The state machines ogygia’s runtime is built on. An app doesn’t import it. | none | Packages |
@ogygia/core, @ogygia/compiler | What ogygia re-exports. Import from ogygia instead. | none | Packages |
Every package except @ogygia/tsdown-plugin-svelte releases at ogygia’s version. Keep them in step.
ogygia
You can import names one by one or as a namespace (import * as ogygia from 'ogygia'). Each name links to its entry on the generated page.
| Export | Kind | What it is | Guide |
|---|---|---|---|
region | function | Makes a held region: region(Component, props, options?). region.snippet() builds a snippet region by hand. | Held regions |
Region | component | Renders a held region, or a promise of one: <Region of={x} />, with an optional placeholder snippet. | Held regions |
isRegion | function | Tells a held region from other values. | Held regions |
preload | function | Fetches a held region’s HTML now, before its schedule. | Warm a region early |
transport | value | The codecs for Kit’s transport hook in src/hooks.ts, so a region can cross from the server. | Add the transport hook |
requestEvent | function | Kit’s RequestEvent inside any component during the server render; null in the browser. | Read the visitor’s request |
keepFallback | function | Called in a server island: keep the page’s fallback and send nothing. | Keep the fallback |
hydratedBy | function | Which schedule woke this island (for example 'interaction'). Call it during setup. | Know when an island is live |
isOgygiaPage | function | true on a csr = false page, false on a page Kit hydrates. For shared code that branches on it. | Share a component with Kit pages |
createContext | function | Svelte’s [get, set, has], keyed by Symbol.for(name) so values reach islands: createContext<T>('name'). | Define a typed context |
setContext | function | Svelte’s setContext that also reaches every island on the page. { islands: false } keeps a key on the server. | Swap the import |
getContext | function | Svelte’s own getContext, re-exported so one import covers both. | Read it |
Provide | component | Gives context to the islands inside it: <Provide values={{ theme: 'dark' }}>. | Provide to one part of the page |
og_derived | function | A derived store that crosses into islands live, with its formula marked by import.meta.og.$. | Derived stores |
script | function | An inline <script> string, written safely, for code that runs before the first paint. | Below |
preference | function | A choice saved in the browser that flips a CSS state with no island: theme, code language, tabs. | Below |
Boundary | component | Renders its children and nothing else. A note for readers around a region; not an error boundary. | none |
Types: RegionValue, AwaitableRegion, InlineRegion, DualRegion, DeferredRegion, RegionOptions, RegionSchedule, RegionData, Fallback (props plus ogygiaFallback, for a server island), TransportCodec, Preference and PreferenceSpec.
The macros (import.meta.og.wire, $, source and the plugins’ own) are rewritten by the build and are not exports. Macros lists them all.
Run code before the first paint with script()
A csr = false page has no client code until its islands wake, so code that must run before the first paint has to be an inline <script> in the HTML: setting the theme with no flash, starting a deferred font. Writing that string inside a component is awkward, because a literal </script> ends the component’s own script.
script() writes it for you. Pass one object with exactly one body key and the tag’s attributes, and you get back a <script>…</script> string to {@html}, usually in <svelte:head>. A function followed by arguments is the shortcut for a plain classic script: script(fn, a, b) means script({ run: fn, args: [a, b] }).
| Body key | Tag | What it is |
|---|---|---|
run (+ args) | <script> or <script type="module"> | A self-contained function, called with args. |
json | type="application/json" | Data for code on the page (JSON.parse(el.textContent)). |
ld | type="application/ld+json" | Structured data for search engines. |
importmap | type="importmap" | Bare specifiers for the page’s module scripts. |
speculation | type="speculationrules" | Pages the browser may prefetch or prerender. |
The function is inlined with Function.prototype.toString, so it has to be self-contained: browser globals only, no imports and no closed-over variables. Values go in args, which are JSON-serialized and passed as parameters. TypeScript rejects args that don’t match run’s parameters and values JSON would change (a Date, a Map, a function).
A run script is classic by default: it runs where it stands, so in <head> it runs before the first paint. type: 'module' gives it module scope, and it then runs after the document is parsed, so code that must apply before paint stays classic. A module also takes async: true, and imports, the modules it needs by name and URL (imports: { carousel: url }). run gets them as one object first, then its args: run: ({ carousel }, n) => …. Never import() inside run: Vite rewrites that for the server, and script() throws (script_run_rewritten).
Other attributes go in the same object: id, nonce and any data-* work on every kind. true writes a bare attribute, and false, null and undefined leave it out. Every value is escaped, and so is every </script and <!-- in the code, so nothing can break out of the tag. Constraints lists the errors.
Save a visitor’s choice with preference()
preference() is a choice a visitor makes once and the whole site remembers: a theme, a code language, a package manager tab. The value lives in localStorage and is mirrored onto <html data-pref-<name>="<value>"> before the first paint, so your CSS shows the right variant with no island and no flash.
Declare it with a name, its values and a default (one of the values, or it throws preference_default_invalid). Put head() in the layout’s head for the no-flash apply, and preference.switch() once for the buttons. Any element with data-pref="<name>" and data-pref-set="<value>" then sets the choice when clicked, through one delegated listener that survives SPA navigations. In island code, set(value) and get() do the same by hand.
<script>
import { script } from 'ogygia';
import fontUrl from '$lib/mono.css?url';
let { children } = $props();
</script>
<svelte:head>
<!-- runs before the first paint -->
{@html script(() => {
try {
const t = localStorage.getItem('theme');
if (t === 'light' || t === 'dark')
document.documentElement.setAttribute('data-theme', t);
} catch {}
})}
<!-- a value it needs goes in args -->
{@html script({
run: (href) => {
addEventListener(
'load',
() => {
const l = document.createElement('link');
l.rel = 'stylesheet';
l.href = href;
document.head.appendChild(l);
},
{ once: true }
);
},
args: [fontUrl]
})}
<!-- data, not code -->
{@html script({
ld: {
'@context': 'https://schema.org',
'@type': 'WebSite',
name: 'Docs'
}
})}
</svelte:head>
{@render children()}<script>
import { preference } from 'ogygia';
let { children } = $props();
const lang = preference({
name: 'code-language',
values: ['ts', 'js'],
default: 'ts'
});
</script>
<svelte:head>
{@html lang.head()}
{@html preference.switch()}
</svelte:head>
<button data-pref="code-language" data-pref-set="ts"
>TypeScript</button
>
<button data-pref="code-language" data-pref-set="js"
>JavaScript</button
>
{@render children()}
<style>
:global(
:root[data-pref-code-language='js'] [data-variant='ts']
),
:global(
:root[data-pref-code-language='ts'] [data-variant='js']
) {
display: none;
}
</style>Import attributes
These are written on a component import, not called. Regions explains each one, and Constraints lists the build errors.
| Attribute | What it sets | Values |
|---|---|---|
wake | When an island’s JavaScript runs. On a render: 'live' lake, when it revalidates. | 'load', 'idle', 'visible', 'interaction', a media query such as '(min-width: 800px)', 'none' (a lake) |
render | Where the HTML comes from. | 'static' (default), 'deferred' (a server island), 'live' (a lake that refreshes) |
fetch | When a render: 'deferred' hole’s HTML arrives. | 'load' (default), 'idle', 'visible', 'interaction', a media query |
prefetch | When a hole’s HTML is warmed, ahead of its fetch. | 'load', 'idle', 'visible', a media query |
keep | Keeps a live island across SPA navigations. | a name |
stitch | Fills a hole into a stored page as it’s served. | 'serve', 'edge' |
preset | Uses a named bundle from ogygia({ presets }). Stands alone. | a preset name |
region | Marks a held region with no schedule. Stands alone. | 'raw' |
ogygia/vite
ogygia(options) is the Vite plugin. List it before sveltekit(), and before any other ogygia plugin. Every option is optional, and a key it doesn’t have fails the build (option_unknown). The full types are on the generated page.
| Option | Default | What it does |
|---|---|---|
visible | none | { margin }: the default rootMargin for visible islands and holes. |
presets | {} | Named bundles of attributes and tuning options. Presets. |
router | true | The SPA router and its parts. Router. |
ttl | 3600 | Seconds a hole’s signed URL stays valid, held between 60 and 86400. |
maxPageAge | 691200 (8 days) | Seconds after expiry a cached page’s hole may still renew itself. |
rateLimit | { max: 60, windowMs: 60_000 } | Requests per window per client address on the region endpoint, or false. |
sessionCookie | false | A cookie name to seal into every hole’s signature. |
importKeys | the standard names | Renames wake, fetch, render, preset and region in your with { … }. |
Every feature that lives in its own package is a separate Vite plugin, listed beside ogygia(), where ogygia() finds it. Each keeps its own options. See Packages.
visible
Sets the default rootMargin for visible islands and server islands, so they start loading a little before they scroll into view. A preset’s margin overrides it for the imports that use the preset.
presets
A preset is a named bundle that an import uses with with { preset: 'name' }. It speaks the same grammar as an inline mark (render, wake, fetch, prefetch, keep, stitch), plus the tuning options that aren’t allowed inline:
| Field | For | What it does |
|---|---|---|
margin | visible | The rootMargin for this preset. |
maxAge | a hole | Lets the browser cache the hole’s HTML: Cache-Control: private, max-age=…. Absent or 0: no-store. |
maxAge | a render: 'live' lake | How stale the lake may get before it revalidates. |
onExpire | a render: 'live' lake | Past maxAge: 'fetch' again, or 'empty' the lake. |
revalidate | a render: 'live' lake | When it revalidates; defaults to its wake. false turns it off. |
A preset sets render or wake. An empty preset, or one with a key it doesn’t have, fails when the config loads (preset_empty, preset_key_unknown). A preset with neither fails where an import uses it (region_import_invalid).
The build accepts stitch in a preset, but the OgygiaPreset type doesn’t list it yet, so it’s a type error in vite.config.ts (#2278).
maxAge is signed into the hole’s URL, so a copied URL can’t be pointed at a longer cache. prefetch warms a hole’s HTML into the page’s store on its own schedule while the swap still waits for fetch, so an on-demand hole has its bytes before the first hover (Warm it before it swaps).
A bare number changes units
On a hole, maxAge: 60 is 60 seconds, an HTTP max-age. On a render: 'live' lake it’s 60 milliseconds, a JavaScript staleness. Duration strings ('30s', '5m', '1h') mean the same everywhere, so use them.
router
The SPA router is on by default for the whole app. This option is the only place its settings live.
| Setting | What it does |
|---|---|
true (default) | Router on, view transitions on, form continuity on. |
false | No router. Its code is left out of the build, and links are full page loads. |
{ viewTransitions: false } | Router on, no view transitions. |
{ forms: false } | Router on, but half-filled form fields aren’t carried across navigations. |
{ serverDelta: true } | Off by default. The server skips re-rendering islands the browser already holds. |
Form continuity keeps password fields like any other field (#2274): put data-ogygia-no-keep on them, or turn it off with forms: false. With router: false, invalidateAll() may not refresh the page (#2277). SPA router covers each setting.
ttl
How long a hole’s signed URL stays valid, in seconds: 3600 by default, held between 60 and 86400. Keep it short, so a copied URL expires.
Holes outlive it where they have to. Prerendered and postrendered pages sign their holes for 10 years, so keep OGYGIA_SECRET stable. On a page whose load marks it shared-cacheable, with setHeaders({ 'cache-control': 'public, s-maxage=604800' }), an anonymous hole is signed for the page’s cache life. Set that header from a load: a header a handle sets after the render is too late for the signature.
maxPageAge
How long after its URL expires a hole on a cached page may still renew itself, in seconds: 8 days by default, 0 to turn renewal off. Past it, the hole keeps its fallback and its request gets 403 with x-ogygia-deny: renew-window. A value that isn’t a number fails the build (max_page_age_invalid).
Raise it when your CDN keeps pages longer than 8 days and the page’s own cache-control doesn’t say so:
It isn’t a longer ttl: a renewed URL still lives ttl, and a hole bound to a session never renews. A renewed URL replays the props signed into it, so keep a hole’s props to routing keys (a locale, a page id) and read anything sensitive when it renders.
rateLimit
A budget per client address on the region endpoint: { max: 60, windowMs: 60_000 } by default, or false to turn it off. Each hole counts as one request, including each hole in a batch. Over budget, the endpoint answers 429.
The client address is what your adapter gives (event.getClientAddress()). Behind a reverse proxy or a load balancer, tell the adapter which header holds the visitor’s address (adapter-node: ADDRESS_HEADER, with XFF_DEPTH for X-Forwarded-For). Otherwise every visitor shares the proxy’s budget, and the server warns once with rate_limit_shared_address.
sessionCookie
The name of a cookie to seal into every hole’s signature: false by default. With it set, a copied hole URL fails without the visitor’s cookie. Prerendered holes and holes rendered with no such cookie stay unbound, and a bound hole never renews.
importKeys
Renames the attribute keys ogygia reads, for when another tool already uses wake, fetch, render, preset or region on the same imports: importKeys: { wake: 'hydrate' }. Each name must be a distinct JavaScript identifier (import_key_invalid, import_keys_not_distinct). Preset definitions keep the standard names.
OGYGIA_SECRET
The environment variable that signs hole and live-region URLs. Set it to a random value of at least 16 bytes; a production build refuses a shorter one (secret_too_short). Without it, each build signs with its own random key, so every deployment that serves your pages or your endpoint needs the same value. A hole signed with one key and checked against another is refused (x-ogygia-deny: foreign-key).
If your server process never sees its runtime environment, pass the secret to the handle. A value from $env/static/private is read at build time:
handle({ secret }) wins over the variable, and an empty value counts as none. Both sign the same way. The server decides its key the first time it signs or checks a URL and keeps it for the life of the process; a different secret after that throws in dev and is logged in production (secret_conflict).
A hole’s URL names the component it renders, so a page cached across a deploy keeps its holes as long as those components still exist. A hole whose component was moved, renamed or removed is refused (x-ogygia-deny: unknown-id) and keeps its fallback.
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia({ visible: { margin: '200px' } }),
sveltekit()
]
});import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [
ogygia({
presets: {
chart: { wake: 'visible', margin: '200px' },
pricing: {
render: 'deferred',
fetch: 'load',
maxAge: '1h'
},
menu: {
render: 'deferred',
fetch: 'interaction',
prefetch: 'idle'
},
ticker: { render: 'live', wake: 'idle', maxAge: '10m' }
}
}),
sveltekit()
]
});<script>
import Chart from '$lib/Chart.svelte' with {
preset: 'chart'
};
</script>
<Chart />import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { defineConfig } from 'vite';
export default defineConfig({
plugins: [ogygia({ maxPageAge: 30 * 24 * 3600 }), sveltekit()]
});import { OGYGIA_SECRET } from '$env/static/private';
import * as ogygia from 'ogygia/server';
export const handle = ogygia.handle({ secret: OGYGIA_SECRET });ogygia/server
handle(options) is the SvelteKit server handle. It serves the region endpoint (each hole’s request and the router’s batch), injects the runtime and the page’s seeds, and runs the server half of every listed plugin. ogygia/hooks is the same module.
| Export | What it is |
|---|---|
handle() | The handle. Options: endpoint (default /__ogygia__, not under /_app) and secret (see above). |
document() | Renders a held region into a whole HTML Response, for a route with no page (Serve a region as a whole page). |
transport | The server’s side of the region codecs. |
An HTML pass of your own is not a handle option: it’s rewrite() from @ogygia/rewrite, listed before ogygia.handle(). Passing transform throws handle_transform_moved.
import * as ogygia from 'ogygia/server';
export const handle = ogygia.handle();ogygia/app
$app/navigation for islands. On a csr = false page Kit’s client never starts, so Kit’s own functions have nothing to drive; these drive the ogygia router. See Navigate from code.
goto · invalidate · invalidateAll · preloadData · preloadCode · beforeNavigate · afterNavigate · disableScrollHandling (does nothing; the router handles scroll) · bust_page_cache() (drops every prefetched page) · spa_html_cacheable(cacheControl, setCookie) (whether the router may keep a prefetched page).
The navigation types (NavTarget, BeforeNavigation, AfterNavigation and the callback types) are on the generated page.
ogygia/events
The event layer: a typed stream of what ogygia did (island wakes, server renders, navigations) and the helpers to read it (add_sink, snapshot, clear). It’s compiled into your app only when a plugin asks for it, as devtools() does. Event stream shows how to use it, and @ogygia/insights turns the stream into findings.
Build helper plugins
These change how your app is built, not what a page can do. Each is a package of its own, listed beside ogygia(), with its own section in these docs. Note where each factory is imported from.
dataShake()
dataShake() from @ogygia/data-shake/vite ships only the page.data keys your islands read, and lets a server island that reads none skip the page lookup. No options. postrender() requires it. See Datashake.
barrels()
barrels() from @ogygia/barrels rewrites barrel imports to the files they name. Options: packages, force, keep, importers, followPackages, report, debug. The old ogygia({ barrels }) option fails the build as an unknown option (option_unknown), whose page names barrels(). See Barrels.
bake()
bake() from @ogygia/bake compiles import.meta.og.bake(fn). No options. See Bake.
image()
image() from @ogygia/image/vite compiles import.meta.og.image(), .glob() and .card(), and serves the files. <Img> from @ogygia/image renders them. See Image, and Options for every option.
jumpstart()
jumpstart() from @ogygia/jumpstart builds the server into a few files, for a fast cold start. One option, external. See Jumpstart.