From c257f830f1bfd590c365b47ce85b4a579696410e Mon Sep 17 00:00:00 2001 From: ChristopherPHolder Date: Sat, 28 Nov 2026 09:39:13 +0100 Subject: [PATCH] docs: a guide to running streamed pages in production Status codes and redirects, crawlers and metadata, Content Security Policy, caching, Web Vitals, request context, and proxies, ending in a checklist. Limitations links to it, and says the setups without @angular/ssr don't hand the app the request. Closes #104 --- apps/docs/src/app/docs/nav.ts | 12 +- apps/docs/src/content/guides/production.md | 150 ++++++++++++++++++ .../docs/src/content/reference/limitations.md | 9 +- 3 files changed, 169 insertions(+), 2 deletions(-) create mode 100644 apps/docs/src/content/guides/production.md diff --git a/apps/docs/src/app/docs/nav.ts b/apps/docs/src/app/docs/nav.ts index 38ef9cb..4608eae 100644 --- a/apps/docs/src/app/docs/nav.ts +++ b/apps/docs/src/app/docs/nav.ts @@ -286,7 +286,8 @@ export const DOCS: DocSection[] = [ { id: 'guides', title: 'Guides', - description: 'Making a page stream, checking that it does, and getting it through a proxy.', + description: + 'Making a page stream, checking that it does, getting it through a proxy, and running it in production.', groups: [ { pages: [ @@ -334,6 +335,15 @@ export const DOCS: DocSection[] = [ 'Compression, Nginx, CDNs and timeouts: what holds a streamed response back, and how to check that it does not.', load: () => import('../../content/guides/streaming-through-proxies.md'), }, + { + dir: 'guides', + slug: 'production', + title: 'Going to production', + headline: 'Streamed Angular SSR in production', + description: + 'Status codes, crawlers and metadata, Content Security Policy, caching, Web Vitals and request context, with a checklist.', + load: () => import('../../content/guides/production.md'), + }, { dir: 'guides', slug: 'service-worker', diff --git a/apps/docs/src/content/guides/production.md b/apps/docs/src/content/guides/production.md new file mode 100644 index 0000000..b55e6b9 --- /dev/null +++ b/apps/docs/src/content/guides/production.md @@ -0,0 +1,150 @@ +A streamed page is sent before it is finished, and that changes a few things a +server-rendered app usually takes for granted: the status code, what crawlers +and caches get, the security policy, and how the page loads. This page goes +through them, and ends in a checklist. + +## Status codes and redirects + +The status and headers go out with the shell, before any data has arrived. A +request that fails later can't turn the response into an error page, and a +`404` has to be known before the first byte. + +- **With the Angular CLI**, `@angular/ssr` keeps its server routes, so give a + route its `status` there, and its redirects. A component can still set + `RESPONSE_INIT` until the shell goes out: decide the status from the URL, or + from a route resolver, whose data is there before the route renders. Anything + that arrives with a chunk comes too late. See + [What `@angular/ssr` still does](../getting-started/angular-cli.md#what-angularssr-still-does). +- **On the other setups** every page is a `200`, a not-found page included. + A server that knows its routes sets the status from outside, keeping the + streamed body, as [the demo's Worker](../../../../cloudflare-demo/src/worker.ts) + does: + + ```ts + const response = await pages.fetch(request, env); + if (isPage(url.pathname) || !response.ok) { + return response; + } + return new Response(response.body, { status: 404, headers: response.headers }); + ``` + + Redirects are the same: answer them before the request reaches the handler. + +A page that loads and then finds out its data doesn't exist, a product that was +deleted, still answers `200`. Show a not-found state in the block, and keep +such pages out of search with `` set in +the shell, if the route can tell by then. + +## Crawlers and metadata + +Crawlers get the same stream as everyone. One that runs scripts, as Google's +does, sees the page as a reader does, once the stream has ended. One that +doesn't keeps the shell: each block's loading state, with the streamed markup +in `