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.
Why this matters
Static output and one endpoint turn routes into crawlable URLs.
Before you start
- SvelteKit project with a Node or static adapter
- Production origin available to the build
How to apply it
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.
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.
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.
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.
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 playbook · curated entry · report an error
Framework notes
sveltekit
Set `export const prerender = true` in `+layout.server.ts` and add `entries()` for dynamic routes; the `sitemap.xml/+server.ts` GET handler can be prerendered too.