Skip to content

@ogygia/jumpstart

Jumpstart

@ogygia/jumpstart builds the server into a few files: dependencies bundled in, the framework in one chunk, and each region registry in a chunk of its own. A cold start on a slow serverless box then reads a few files instead of hundreds, and pages are served byte for byte as before.

On this page

A SvelteKit server build puts nearly every module in a file of its own, and leaves dependencies in node_modules, where Node loads them one file at a time. On a fast disk you never notice. On a slow serverless box, reading those files is most of a cold start: the first request after the instance starts waits for hundreds of small reads before your code runs.

jumpstart() changes the shape of the server build only. Dependencies are bundled in, the framework and every dependency go in one chunk, and each region registry gets a chunk of its own, loaded only by pages that use it. In ogygia’s own test app, importing the module of a page with a 24-block registry and a 120-file dependency loads more than 120 files without it and six or fewer with it.

import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { jumpstart } from '@ogygia/jumpstart';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [ogygia(), jumpstart(), sveltekit()]
});

Installation

Install the package and list its plugin beside ogygia(), before sveltekit(). The factory comes from the package root, not /vite. It takes one option, external: the packages that can’t be bundled. A key it doesn’t know fails the build with jumpstart_option_unknown instead of being ignored.

pnpm add @ogygia/jumpstart
import { sveltekit } from '@sveltejs/kit/vite';
import { ogygia } from 'ogygia/vite';
import { jumpstart } from '@ogygia/jumpstart';
import { defineConfig } from 'vite';

export default defineConfig({
  plugins: [
    ogygia(),
    jumpstart({ external: ['sharp'] }),
    sveltekit()
  ]
});

Server chunks

In the server build, and only there:

  • Every dependency is bundled in (Vite’s noExternal), except the packages in external. Packages linked from your workspace count as dependencies too.
  • server: the framework (Svelte, Kit, ogygia) and every dependency, in one chunk.
  • regions-<name>: one chunk per region registry, with the components its regions render. Only a page that imports the registry loads it (Region registries).
  • shared: your own code that a registry shares with the rest of the app, so a page outside the registry never loads the registry.

The rest of your app’s code is split as Kit splits it, per route.

.svelte-kit/output/server/
  chunks/server.js            the framework and every dependency
  chunks/regions-blocks.js    src/lib/blocks.ts and the blocks it marks
  chunks/shared.js            app code the registry and other pages both use
  entries/pages/…             each route, as Kit builds it

What doesn’t change

  • The client build. Islands, the runtime and every browser file are built as before.
  • Dev. The dev server is untouched.
  • Your pages. Every page, and every hole it asks for, is served byte for byte as without jumpstart(). ogygia’s own tests build each page both ways and compare them.
  • When each module runs. See Run order.

Run order

Each module’s top-level code runs when it would without jumpstart(), whatever chunk it’s in. A dependency that only some pages import runs when the first of them loads, not at server start. One that only a page’s component imports doesn’t run when Kit’s build reads the routes either, while one that a +page.server.js or +page.js imports runs then, as it does without jumpstart(). So a module that formats a message with a locale your hooks set, or opens a connection, behaves the same.

The server build turns on Rolldown’s strictExecutionOrder for this, which wraps each module in a small function its importer calls. That costs some size and time: on a 225-block app, the server output is about a tenth larger, and the first request to its block page about 10 ms slower, than the same chunks without it. Start plus that first request still takes about half the time it takes without jumpstart().

The modules a page loads run in source order: each module’s imports, in the order it lists them, before its own code, the way Node runs unbundled ES modules. Two things differ from a build without jumpstart():

  • Without it, a page’s dependencies are imported from node_modules and run before the page’s own modules, even when the page lists its own first. With it, they run in the order the page lists them.
  • A dependency that awaits at its top level holds back the modules a page lists after it until it finishes. Without jumpstart() they run while it waits.

When it builds without it

strictExecutionOrder needs Rolldown 1.3.3 or later (Vite 8.4 installs it with a fresh lockfile). An older Rolldown never finishes a SvelteKit 2 server build with it.

Rolldown also can’t yet run a module that awaits at its top level in, or below, a cycle of static imports under it, such as a barrel index.js that re-exports db.js, which awaits, and auth.js, which imports the barrel back. The server would never finish starting.

In both cases jumpstart() builds without strictExecutionOrder, so every bundled dependency runs at server start (and when Kit’s build reads the routes), and the build says why in one line (jumpstart_run_order). For the await under a cycle, vite build finds it after the first server build and builds the server again without it. A build started from code, with Vite’s build(), can’t build again, so it stops and names the module and the cycle (jumpstart_await_cycle). Breaking the cycle (import db.js itself, not the barrel) or moving the await into a function brings the run order back.

A strictExecutionOrder your Vite config sets for the server build is kept as it is.

Adapters

adapter-node and adapter-vercel keep the chunks as built. An adapter that bundles the server again with its own tool may merge or split them its own way, and the deploy then has whatever shape that tool gives it.

Packages in external stay imports, so the deploy needs them installed where the server runs. With adapter-node, that’s the node_modules beside the build: keep them in your dependencies.

Measuring

What matters is the time from process start to the first response on a cold instance. Build with and without jumpstart(), start each build in a fresh process, and time the first request to a heavy page and to a light one. The file count is a quick proxy: find build/server -name '*.js' | wc -l before and after.

Integrations

  • Content blocks. A block registry is the case jumpstart() was made for: a CMS page loads its blocks’ chunk, and every other page skips it.
  • Image. sharp and @resvg/resvg-js load native addons, so list sharp in external when your server makes images, and @resvg/resvg-js too if it draws social cards.

Package contents

PageWhat it covers
External packagesexternal, which packages need it, the build’s line about what stayed outside.
Region registriesWhat counts as a registry, its chunk’s name, the shared chunk, and edge cases.
@ogygia/jumpstartThe generated API reference for jumpstart() and its options.