Skip to content

SvelteKit 2 SSR pages have no JS preloads once you strip the Link header (modulepreload tags are prerender-only)

SvelteKit 2.70 app on adapter-node behind Cloudflare. To avoid Cloudflare turning SvelteKit's Link preload header into 103 Early Hints (which hung pages over HTTP/3, sveltejs/kit discussion 6519), the handle hook calls response.headers.delete('link'), on the assumption that the same preloads are also emitted as <link rel="modulepreload"> tags in the HTML head. Lighthouse then showed every route's node chunks at depth 3 of the network dependency tree (document -> entry/app.js -> nodes/*.js) and data fetches at depth 4, with long render delay on mobile. Viewing source of an SSR'd page shows only the two inline import("./_app/immutable/entry/start.js") / app.js calls and stylesheet links: zero modulepreload or preload tags. Default kit.output.preloadStrategy ('modulepreload') was in use; nothing in svelte.config.js touched preloading.

(Restored 2026-11-23: first published 2026-10-03; the original post was overwritten by a since-fixed dedup bug.)

1 solution
ranked by outcome — not votes
Accepted

With the default preloadStrategy: 'modulepreload', SvelteKit only writes <link rel="modulepreload"> tags into the HTML while prerendering. In @sveltejs/kit/src/runtime/server/page/render.js (2.70.3):

for (const path of included_modulepreloads) {
  link_headers.add(`<${encodeURI(path)}>; rel="modulepreload"; nopush`);
  if (options.preload_strategy !== 'modulepreload') {
    head.add_script_preload(path);          // always emitted
  } else {
    head.add_link_tag(path, ['rel="modulepreload"']);
  }
}
// ...
add_link_tag(href, attributes) {
  if (!this.#prerendering) return;        // SSR: dropped
  this.#link_tags.push(`<link href="${href}" ${attributes.join(' ')}>`);
}

So for SSR responses the Link header is the only carrier of JS preloads. Deleting it in handle removes all of them, and the browser discovers each route chunk only after the entry module executes.

Fix (keeps the Link-header strip for the Cloudflare issue):

// svelte.config.js
const config = {
  kit: {
    adapter: node(),
    output: { preloadStrategy: 'preload-js' }
  }
};

preload-js goes through head.add_script_preload, which is unconditional and emits <link rel="preload" as="script" crossorigin="anonymous" href=...> for every dependency in the SSR HTML. Verify with curl -s https://your.site/some/route | grep -c 'rel="preload" as="script"' (was 0). Alternative: re-add the tags yourself in transformPageChunk, or only drop the header for the problematic edge instead of deleting it everywhere.