Streaming SSR for Angular
Don't make the whole page wait for its slowest part
angular-ssr-stream sends a server-rendered Angular page straight away and streams the slow parts into it as they finish, in the same response. Angular hydrates each part as it lands.
A page is as slow as its slowest request
Angular renders a page on the server and sends it whole. Take the product page above: the product renders at once, its reviews take one second and its recommendations three. Sent whole, that is a blank page for three seconds. Streamed, the reader has the product straight away and the reviews after one.
Hydration follows the HTML. Sent whole, nothing on the page responds to a click until all of it has arrived and Angular has hydrated all of it. Streamed, Angular hydrates each part as it lands, so the product can be used while the reviews are still loading.
Both pages are complete at the same moment: streaming does not make a slow request faster. It stops the rest of the page, and the browser's work on styles, fonts and scripts, from waiting for it.
What angular-ssr-stream does
The server keeps the response open and adds to it. There is no second request and no fetching from the browser.
The shell goes out at once
The server sends everything that does not wait for data, with a placeholder for each part that does. The browser loads Angular and hydrates the shell while the response is still open.
Each slow part follows
When a request finishes, the server renders the part that waited for it and adds it to the response. A small inline script puts it in place, whether or not Angular is running yet.
Angular hydrates it
The part hydrates against the streamed markup when its trigger fires. Its data came with it, so nothing is fetched twice.
Step through one page load. Its two slow parts arrive in the order their data does, not the order of the page, and each one hydrates on its own.
The browser asks for the page
The server starts rendering. The page has two parts that wait for an API: recommendations, which take 3 seconds, and below them reviews, which take 1. Nothing has been sent yet.
What the server has sent
Nothing has arrived yet.
arrived in this step
What the browser shows
Blank page
In your app, a slow part is a @defer block with a hydrate trigger. The rest is a few providers in the app config and a server entry for where the app runs.
Try it in your app
Install the core, add its providers and write the server entry. Each of the 16 runtimes has a setup page of its own, from the app config to running it.
Get startedWatch it happen
The live demo streams a real widget into an open page and times each step, then takes a response apart flush by flush as it arrives.
Open the live demoPick your runtime
One setup page per server or platform. You need only yours.
Angular CLI
Node and its frameworks
- Node node adapter
- Express node adapter
- Fastify fastify adapter
- NestJS nestjs adapter
- Koa node adapter
Edge and other runtimes
- Cloudflare Workers cloudflare adapter
- Hono core only
- Deno core only
- Bun core only
- Fastly Compute core only
Hosted platforms
Getting started
What it is, what it needs, and which packages to install.
Guides
Making a page stream, checking that it does, getting it through a proxy, and running it in production.
How it works
What Angular has and what it lacks, why stream out of order, what goes over the wire, and what does not work yet.
API reference
Every export of every package, in the order of the runtimes.