Skip to content

@ogygia/jumpstart

Region registries

A region registry, a .ts or .js module that marks region imports, gets a server chunk of its own named regions-<file>, with the components its regions render. Only a page that imports the registry loads it, and code it shares with other pages goes in a shared chunk.

On this page

A page builder renders blocks from a registry: one module that imports every block a CMS page might use. Bundled with the rest of the server, that registry would make every page load every block. jumpstart() gives each registry a chunk of its own instead, so a page with no blocks starts as fast as before, and a CMS page loads its blocks in one read.

import Hero from './blocks/Hero.svelte' with {
  wake: 'visible'
};
import Gallery from './blocks/Gallery.svelte' with {
  wake: 'visible'
};
import Quote from './blocks/Quote.svelte' with { wake: 'none' };

export const blocks = { Hero, Gallery, Quote };

What counts

A registry is a script module, .ts or .js (also .mts, .cts, .mjs, .cjs), that marks region imports, as above. A .svelte component that marks regions is not a registry: its regions stay where the bundler puts them.

Chunk names

Each registry’s chunk is named regions- and the registry’s file name without its extension, with anything but letters, digits, _ and - turned into -: src/lib/blocks.ts becomes regions-blocks. Two registries with the same file name get regions-blocks and regions-blocks-2, in path order. No registry can take the name server or shared, whatever its file is called.

The chunk holds the registry module, the components its regions render, and the modules ogygia writes for those regions.

Shared code

App code that a registry’s blocks import and that a page outside the registry also imports goes in a chunk called shared. Without it, the bundler might put that code in the registry’s chunk, and the light page would load every block to get it. Code only the registry reaches is left to the bundler, which never makes a light page load it. Dependencies are never in shared: they’re in server.

// imported by a block and by a page with no blocks: goes in `shared`
export const price = (cents: number): string =>
  `${(cents / 100).toFixed(2)}`;

Edge cases

  • A component both a registry and a .svelte file mark stays where the bundler puts it, outside the registry’s chunk, since a page that never imports the registry renders it too.
  • A component two registries mark goes with the first registry by path.
  • An app with no registry builds with no regions-* chunk, and only server changes its shape.
  • A dependency a region is built from (a component from an npm package marked in your registry) goes with the registry, not in server.