Skip to content

Lack of true Edge Middleware support blocks prerender + dynamic behavior (e.g. i18n redirects) #13774

@Papsanly

Description

@Papsanly

Describe the problem

Summary:

SvelteKit currently does not support a true equivalent of Next.js middleware.ts — a middleware layer that runs before a static asset is served (e.g. prerendered .html). This severely limits the ability to implement common use cases like internationalization redirects, A/B testing, geolocation-based content, and cookie inspection without giving up SSG.

Problem:

In Next.js, middleware.ts runs before a static page is served from the CDN. This allows developers to:

  • Read headers and cookies

  • Dynamically redirect (/ → /en)

  • And still serve prerendered content

In SvelteKit:

  • hooks.server.ts only runs on SSR or Edge runtime

  • But does not run at all for prerendered routes

So, to implement dynamic logic (e.g. locale detection), we must disable prerendering, which:

  • Slows down response times

  • Breaks CDN-level caching

Describe the proposed solution

Possible solutions:

  • Add a middleware.ts-like system that runs before routes are resolved, even for static pages

  • Allow limited hooks to run during static asset delivery when deployed via Vercel/Cloudflare

  • Add official integration with Vercel's Edge Middleware layer that plays nicely with SvelteKit’s router

Alternatives considered

As a result, we either:

  • Accept client-side FOUC (e.g. for i18n redirects)

  • Or lose SSG/CDN benefits by turning off prerendering

Next.js has solved this very well. SvelteKit currently has no equivalent.

Importance

i cannot use SvelteKit without it

Additional Information

Can the SvelteKit team provide an official position on this limitation, and whether "true edge middleware before static delivery" is on the roadmap?

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions