liveBook · Manning

Prerendering

As explained in Modern Angular

Static site generation is the process of producing web pages as prebuilt files before deployment rather than generating them for each request.

Static site generation produces mainly static Angular pages at build time instead of rendering them for each user request. Angular discovers configured routes during ng build and emits HTML files that can be served immediately, reducing runtime work and JavaScript requirements. section 9.3.3 section 9.4.4

A typical implementation follows this path:

  • Create standalone page components and connect them through Angular routes. section 9.3.3
  • Enable the prerender option in angular.json; optionally provide a routes file for additional paths. section 9.3.3
  • Run ng build and deploy the generated browser folder as static hosting artifacts. section 9.4.4
  • Configure the host to return index.html for unknown routes when client-side navigation or direct route requests would otherwise produce 404 errors. section 9.4.4

HRMS promotional site

An HRMS promotional application containing mostly text and images can prerender its about-us and subscriptions routes. After ng build, the browser output contains an index.html file under the about-us directory and other deployable static artifacts, allowing pages to be served without rendering them on demand. section 9.3.3 section 9.4.4

Listing 9.15 Application routing config
import { Routes } from '@angular/router';
import { AboutUsComponent } from './components/about-us.component';
import { SubscriptionsComponent } from './components/subscriptions.component';

export const routes: Routes = [
    { path: 'about-us', component: AboutUsComponent },
    { path: 'subscriptions', component: SubscriptionsComponent },
];

Inspect the routing configuration that supplies the about-us and subscriptions paths to the prerendering build. section 9.3.3

How Modern Angular covers it

How deep it goes
Explains route discovery, configuration, build output, deployment, and host fallbacks, while deferring server-specific configuration details.
Examples
Demonstrates an HRMS promotional site with about-us and subscriptions routes, generated browser artifacts, and an optional routes file.
What it assumes
Assumes Angular routing and application builds, while showing route definitions and the prerender configuration needed for static output.
What you can do after
Operate/configure Angular prerendering, build static HTML with ng build, and deploy the resulting browser artifacts.
How it connects
Connects prerendering with Angular routing, client-side rendering, server-side rendering, and static hosting.

Also explained in

Compare how 2 books explain prerendering →

Related concepts

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