liveBook · Manning

Server-side rendering

As explained in Pro Angular 16

Server-side rendering is the technique of executing an application on a server to generate HTML that is sent to a browser before client-side code is ready.

Server-side rendering (SSR) executes an Angular application in a server-side JavaScript runtime and sends the browser HTML before the client JavaScript finishes downloading. This reduces the empty-screen delay on slow connections. Hydration then reuses the server-generated elements as the browser application starts. section 8.2 section 27.4

Choose and prepare SSR with these practical considerations:

  • Use SSR when early visible content matters over slow or unreliable networks. section 8.2
  • Budget for substantial server resources and provide a server-side JavaScript runtime; some production platforms may not support this requirement. section 27.4
  • Prepare application features selectively because not every Angular feature works during server rendering. section 27.4
  • Use anchor elements for navigation that must work in HTML-only output, and disable button-driven features until browser JavaScript is ready. section 27.4.4
  • Handle server and browser differences explicitly: for example, replace location-based URLs with a server-safe URL when the web service runs on the same machine. section 8.2.3

Testing an HTML-only application

Run the SSR development command, disable JavaScript in the browser, and request the application. The returned page should display server-generated content; buttons that depend on event handlers remain inactive, while supported anchor navigation works. Re-enable JavaScript to observe hydration and the transition to the browser application. section 27.4.3 section 27.4.4

Table 27.4. The SSR commands
Command
Description
dev:ssr
This command builds and runs the application in development mode, with a watcher and automatic rebuilds and reloads.
build:ssr
This command builds the application for deployment.
serve:ssr
This command executes the production SSR server.

Use the SSR command table to distinguish development, deployment-build, and production-server workflows. section 27.4.3

How Pro Angular 16 covers it

How deep it goes
Explains server execution, hydration, navigation changes, URL handling, commands, and testing, while deferring unsupported Angular features.
Examples
Uses SportsStore URL configuration, Angular Universal installation, anchor navigation, disabled controls, and JavaScript-disabled browser testing.
What it assumes
Assumes an Angular application and command-line package management, while requiring preparation for server execution and browser-only APIs.
What you can do after
Operate/configure Angular Universal SSR, adapt browser-dependent code, test HTML-only output, and distinguish SSR from prerendering.
How it connects
Connects SSR with hydration, prerendering, dynamic modules, Angular Universal, and client-side JavaScript execution.

Also explained in

Compare how 8 books explain server-side rendering →

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.