Astro

Prerender

Prerender is the Astro export that decides whether a single route is built to HTML ahead of time. Set it to true or false per file.

How it is measured

Add export const prerender = true or false at the top of a page or endpoint. In server output, true makes a route static. In static output with an adapter, false makes a route on-demand.

See the result in the build log, which lists prerendered routes. Request a prerendered page twice and confirm identical output. Check on-demand pages for per-request data.

Worked example

A newsroom runs server output. The 40 evergreen explainer pages set prerender = true. The live election-results page leaves it off and reads a database on each request.

On the night, the results page handles 11,000 requests in an hour while the explainers cost nothing at the origin.

How it differs

Prerender is a per-route switch. output: server is a site-wide default. Prerender excludes choosing for other files; the default excludes nuance for single routes.

Common errors

Setting it dynamically from a variable, which Astro cannot read at build. Putting it below imports in a way the compiler ignores. Forgetting it on high-traffic pages. Prerendering a page that reads cookies. Assuming it works without an adapter.

In practice

Review every route and mark each on purpose. Prerender everything that can be the same for all visitors. Watch the build log after each change.

See also

output: server, Static site generation

Sources

Count this on a real site.

Watch my website