liveBook · Manning

Prerendering

As explained in Pro Angular 16

Prerendering is the generation of an application's HTML documents before they are sent to browsers, before client-side JavaScript executes.

Prerendering generates static HTML documents at build time, so browsers can display application content while JavaScript downloads. Unlike server-side rendering, it avoids generating HTML for each request and requires no live application server to produce the pages. section 8.2 section 27.5

The trade-off is that each document is a snapshot: it does not reflect later changes to shared state or data. With JavaScript enabled, rehydration uses the prerendered HTML as the basis for browser-generated content. section 27.5 section 27.5.2

Generate and serve the HTML

Run `npm run prerender` to create static files, then serve the output directory with an HTTP server. Testing with JavaScript disabled shows the HTML pages; enabling JavaScript demonstrates rehydration. section 27.5.2 section 8.2.5

Listing 27.27. Prerendering the example application
npm run prerender

The command used to prerender the example application. section 27.5.2

How Pro Angular 16 covers it

How deep it goes
Defines static route documents generated once, contrasts them with per-request SSR, and notes that snapshots miss later shared-state changes.
Examples
Demonstrates an Angular application prerendered with `npm run prerender`, served over HTTP, and tested with JavaScript disabled or a slow network.
What you can do after
Operate an Angular prerender workflow by generating static files and serving them with a separate HTTP server.
How it connects
Connects server-side rendering to static HTML generation and rehydration to later browser-generated content.

Also explained in

Compare how 2 books explain prerendering →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Pro Angular 16. The section links point to the parts of the book it draws on.