Engineering

Prerendering Angular for Fast, SEO-Friendly Static Hosting

How to ship an Angular application as real HTML pages that work on any static or shared host — including routing, metadata, structured data and Apache configuration.

A traditional single-page application sends the browser an almost empty HTML document and builds the page with JavaScript. That works for logged-in dashboards, but it is a poor fit for marketing sites, documentation and blogs: crawlers and link previews receive little content, and users wait for JavaScript before seeing anything meaningful.

Angular’s build system can prerender routes at build time, producing a complete HTML file per page. The result can be deployed to any static or shared host without running a Node.js server — which is exactly how this website is built and deployed.

Choose static output

With the application builder, set outputMode to static . Every route marked with RenderMode.Prerender is rendered during the build and written to its own directory, such as services/index.html . No server bundle is needed at runtime.

export const serverRoutes: ServerRoute[] = [
  {
    path: 'insights/:slug',
    renderMode: RenderMode.Prerender,
    getPrerenderParams: async () => ARTICLES.map((a) => ({ slug: a.slug })),
  },
  { path: '**', renderMode: RenderMode.Prerender },
];

Parameterised routes need getPrerenderParams so the builder knows which concrete URLs exist. Reading these from the same data source the components use keeps pages and sitemap in sync.

Render metadata on the server

Because prerendering executes your components, anything set through Angular’s Title and Meta services is written into the static HTML. A small SEO service can set the title, description, canonical URL, Open Graph tags, robots directives and JSON-LD structured data for every page in one call.

  • Give every page a unique title and description written for humans.
  • Emit an absolute canonical URL that matches the URL you want indexed.
  • Add structured data such as Organization, Service, BreadcrumbList and Article only when it accurately describes visible content.
  • Remove previously injected JSON-LD before adding new data, so client-side navigation does not duplicate it.

Keep browser-only code out of the render

Prerendering runs without a real browser, so window , IntersectionObserver and canvas APIs are not available. Put that work in afterNextRender , which only runs in the browser after hydration. Animations then enhance content that is already present in the HTML instead of being required to reveal it.

Serve clean URLs on Apache

Prerendered routes become directories containing index.html . On Apache, a few rewrite rules serve /services directly from /services/index.html without a redirect, remove trailing slashes consistently and return a real 404 status for unknown URLs.

DirectorySlash Off
RewriteEngine On

# /services/ -> /services (one canonical form)
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+)/$ /$1 [R=301,L]

# /services -> /services/index.html (internal)
RewriteCond %{DOCUMENT_ROOT}/$1/index.html -f
RewriteRule ^(.+?)/?$ /$1/index.html [L]

ErrorDocument 404 /404.html

Avoid a catch-all rewrite to index.html on a prerendered site. It turns every mistyped URL into a “soft 404” that search engines may treat as duplicate content.

Verify the output

After building, open a few generated files and confirm that headings, body copy, the title, canonical link and JSON-LD are present in the raw HTML. Then test direct loads and refreshes of deep URLs on the real host, run Lighthouse on mobile settings and validate structured data with Google’s Rich Results Test.

Summary

Prerendering gives Angular sites the delivery characteristics of a static site — fast first paint, complete HTML and inexpensive hosting — while keeping the developer experience of a modern component framework.

Suman Ramanandi

Founder & Technical Lead at RaxnexuS, with 8+ years of software development experience.

All insights

Start a conversation

Have an ambitious idea? Let’s engineer it.

Tell us about your product, platform or integration. You will receive a considered response from an engineer — not a sales script.

Engineering Digital Possibilities.

An independent software engineering and digital technology brand, led by Suman Ramanandi. Working remotely with businesses in the United States, United Kingdom, Europe and India.

© 2026 RaxnexuS. All rights reserved.