Performance: Pre-rendering static pages
Pre-rendering static pages improves the initial load speed by serving fully rendered HTML, reducing time to first meaningful paint.
Jump into concepts and practice - no test required
Use Angular Universal to pre-render pages at build time, serving static HTML with minimal client JS.Angular app bootstraps fully on client side, fetching data and rendering content dynamically after load.
| Pattern | DOM Operations | Reflows | Paint Cost | Verdict |
|---|---|---|---|---|
| Client-side rendering only | Many DOM nodes created dynamically | Multiple reflows during JS execution | High paint cost due to delayed content | [X] Bad |
| Pre-rendered static pages | DOM nodes parsed from static HTML | Single reflow on initial load | Low paint cost with immediate content | [OK] Good |
npm run prerender.ng build --prod builds the app but does not pre-render; ng serve --static and npm start prerender are invalid commands.npm run prerender?
"prerender": "ng run my-app:prerender"
dist/my-app/prerendered.dist/my-app/browser is for client build, dist/my-app/server is for server bundle, and dist/my-app/static is not standard.npm run prerender but get an error: "Cannot find module '@angular/platform-server'". What is the likely fix?npm install @angular/platform-server to add the required package.angular.json helps specify routes for pre-rendering?routes array inside prerender options to list paths to pre-render.lazyModules is unrelated to prerender routes, serverTarget defines server build, and outputPath sets build output folder.