Skip to main content
SvelteKit can run with a request-time server or as adapter-static. Use the server hook when requests reach SvelteKit in production; use the prebuild asset writer when the deployment is static.

1. Shared config and SEO instance

src/lib/commerce-seo.config.ts
Keep the SEO instance in server/build-safe code:
src/lib/server/seo.ts

2. Build product/category head data in load

src/routes/product/[slug]/+page.server.ts
Render the model from <svelte:head>:
src/routes/product/[slug]/+page.svelte
Gate site-wide Open Graph/Twitter fallback tags when page.data.seoHead exists. Svelte does not automatically deduplicate a layout’s generic og:title or og:image against page-specific values.
As with other frameworks, add breadcrumbs separately using seo.productUrl() and seo.categoryUrl().

3A. Server deployment: use the SvelteKit handle

src/hooks.server.ts
If your project already has a handle, compose the SEO handle with SvelteKit’s sequence() helper rather than replacing the existing hook. The handler owns Markdown mirrors, content negotiation, llms.txt, sitemap.md, robots, and XML sitemap routes.

3B. adapter-static: prebuild into static/

Static hosting cannot inspect Accept at runtime and cannot build arbitrary /search.md?q=... queries. Generate explicit discovery files before the SvelteKit build: Reuse the shared commerceSeo declaration from step 1 and load local env files before SvelteKit/Vite starts. Running the prebuild as TypeScript keeps that config as a single source of truth:
scripts/generate-seo-assets.ts
package.json
Leave indexable unset in this shared script. Deployment detection then keeps preview builds non-indexable and marks only proven production deployments indexable. Generated SEO files should be gitignored.

Vercel and adapter-static

SvelteKit static output can emit route files such as privacy-policy.html. On Vercel, enable clean URLs so sitemap-advertised extensionless routes resolve:
vercel.json
If /foo.html works but /foo returns 404 in production, the Svelte build succeeded and only host routing is missing.

4. Register WebMCP in root onMount

src/routes/+layout.svelte
Keep the cleanup return last in onMount. Code placed after it is unreachable but still typechecks and builds, which can leave a storefront with no agent tools and no compiler error. Development diagnostics are the fastest way to catch this.

Production checklist

  • choose server hook or static prebuild from the adapter/deployment target
  • static build outputs go to static/, not public/
  • vercel.json uses cleanUrls for adapter-static deployments on Vercel
  • generic layout metadata yields to page seoHead
  • root onMount actually reaches the WebMCP registration block
  • development diagnostics prove registration ran
  • cleanup aborts the registration
  • production deep links and .md mirrors both return 200

Reference starter

Full SvelteKit adapter-static storefront using both packages.