Streaming SSR
Streaming SSR eliminates the tradeoff between fast paint and real content. The shell — chrome, navigation, above-the-fold layout — renders and streams immediately. Slower data-dependent segments arrive over the same connection without blocking the initial paint.
How it works
Without streaming, the server waits for all data to resolve before sending any HTML — slow queries block the entire response. Pulse splits the view into a shell (sent immediately) and deferred segments (sent as placeholders, then replaced when data resolves).
Deferred segments arrive as chunks of HTML over the same connection — no extra requests, no client-side JavaScript required to swap content in.
Enabling streaming
To use streaming, the view is an object of named segment functions rather than a single function. The spec declares which segments are in the shell and which are deferred:
export default {
route: '/dashboard',
server: {
user: async (ctx) => auth.getUser(ctx.cookies.sessionId), // fast
feed: async () => db.feed.latest(), // slow
stats: async (ctx) => analytics.summary(ctx.params.id), // slow
},
stream: {
shell: ['header', 'nav'], // rendered immediately
deferred: ['feed', 'stats'], // streamed when their data resolves
scope: { // which fetchers each segment waits for
header: ['user'], nav: ['user'],
feed: ['feed'], stats: ['stats'],
},
},
view: {
header: (state, server) => `
<header class="site-header">
<a href="/">Dashboard</a>
<span>Hello, ${server.user.name}</span>
</header>
`,
nav: () => `
<nav>
<a href="/dashboard">Home</a>
<a href="/settings">Settings</a>
</nav>
`,
feed: (state, server) => `
<section class="feed">
${server.feed.map(item => `<article>${item.title}</article>`).join('')}
</section>
`,
stats: (state, server) => `
<div class="stats">
<p>Page views: ${server.stats.views}</p>
<p>Conversions: ${server.stats.conversions}</p>
</div>
`,
},
}
Deferred placeholders
While deferred segments are loading, Pulse renders a <pulse-deferred id="pd-[name]"> placeholder in their place. When a segment resolves, its HTML is streamed in a <template> tag alongside a small nonce'd inline script that swaps the placeholder for the template's content — no client JS framework involved, just replaceWith().
hydrate omitted).Server data and streaming
Every server fetcher starts at once, in parallel. What streaming changes is what each part of the page waits for. Declare stream.scope to say which fetchers each segment needs: the shell is written as soon as its own fetchers resolve, a slow fetcher that only a deferred segment uses never holds it up, and each deferred segment streams as soon as its fetchers resolve:
server: {
user: async (ctx) => auth.getUser(ctx.cookies.sessionId), // fast
feed: async () => db.feed.latest(), // slow
},
stream: {
shell: ['header'],
deferred: ['feed'],
scope: { header: ['user'], feed: ['feed'] }, // the header never waits for the feed
},
scope (or all of them, if you omit it) is given every fetcher, so it waits for all of them. Split data across named fetchers, as above, so that scope has something to separate: one fetcher that returns everything cannot be waited for in parts.When to use streaming
| Scenario | Use streaming? |
|---|---|
| Page with fast server data (< 20ms) | No — standard SSR is simpler and fast enough |
| Page with slow database queries | Yes — stream the shell while data loads |
| Pages with above-the-fold and below-the-fold content | Yes — shell renders above the fold immediately |
| API or raw response endpoints | No — use raw responses |
Server-level streaming option
Streaming is enabled by default in createServer. Disable it globally with stream: false:
createServer(specs, {
stream: false, // disable streaming for all specs
})
Even with global streaming enabled, only specs that declare a stream field will use chunked responses. All other specs use regular buffered SSR.