---
title: "Add prerendering and a sitemap endpoint"
description: "SvelteKit renders pages on the server by default, so crawlers already receive HTML, but every request still needs a render. Enable prerendering for content routes with export const prerender = true and generate a sitemap from src/routes/sitemap.xml/+server.ts so the file exists at build time."
url: "https://seo-mcp.io/t/add-prerendering-and-a-sitemap-endpoint"
---

# Add prerendering and a sitemap endpoint

SvelteKit renders pages on the server by default, so crawlers already receive HTML, but every request still needs a render. Enable prerendering for content routes with export const prerender = true and generate a sitemap from src/routes/sitemap.xml/+server.ts so the file exists at build time.

## Prerequisites

- SvelteKit project with a Node or static adapter
- Production origin available to the build

## Steps

1. **Enable prerendering** — Add export const prerender = true to the root layout server file, or set it per content route. For dynamic routes export entries() returning every slug so the build knows what to render.
   Check: The build log lists content routes as prerendered and writes HTML into .svelte-kit/output/prerendered.
2. **Add the sitemap endpoint** — Create src/routes/sitemap.xml/+server.ts with export const prerender = true and a GET function returning new Response(xml, { headers: { 'content-type': 'application/xml' } }).
   Check: After the build, .svelte-kit/output/prerendered/sitemap.xml exists and parses as XML.
3. **Build absolute URLs** — Read the origin from $env/static/public, for example PUBLIC_SITE_URL, and join it with each canonical path. Escape ampersands in loc values and use ISO dates for lastmod.
   Check: Every loc in the output starts with https and matches a prerendered route.
4. **Reference it from robots.txt** — Add static/robots.txt containing Sitemap: your production domain/sitemap.xml alongside the allow and disallow rules, so crawlers discover the file without a submission.
   Check: curl -s your production domain/robots.txt returns 200 and contains the sitemap line.
5. **Verify in production** — Fetch the sitemap and one listed page, confirm the page canonical matches the loc, then submit the sitemap in Search Console and watch the discovered count.
   Check: curl -s your production domain/sitemap.xml returns 200 and ten sampled loc URLs each return 200.

## Source

@seo-mcp on 2026-10-19: https://kit.svelte.dev/docs/page-options#prerender

Canonical: https://seo-mcp.io/t/add-prerendering-and-a-sitemap-endpoint
