-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support <link rel="modulepreload"> for SSR #8549
Comments
I'm wondering if we should print a warning or something similar when the header becomes too long so that it's easier to discover. |
Vite polyfills I'm not sure how we'd print a warning because we're not sure what too long is as it depends on the user's setup The reason we thought the header approach was interesting is that we could send the headers before generating the body which would provide more of a performance boost. But the length issue and not working in other browsers are both big caveats, so I'm not sure it's the best approach. I'd probably support an option and changing the default. |
As far as browser support goes, it seems like chrome between 66 and 103 works with
Correct, but the polyfill only works after The header approach is certainly very interesting, but I don't think it should be enabled by default given the length issue — especially since, as you correctly noted, we can't generate a warning. For now it appears that |
On a related note — if svelte-kit supports HTML response streaming, the response fragment with links can probably be flushed before rendering the main content. This preload will be invalidated if page handler redirects or throws, but same applies to header approach. Not sure if svelte-kit supports, or plans to support, HTML streaming? To add more speculation, HTML links can be compressed (they contain a lot of repetition), while I'm not sure if header compression is applied in common setups. |
Not currently. We've talked about flushing |
@Rich-Harris you removed the prerendering check in the "separate app/framework" PR, do you want to reconsider the headers or can this be closed? |
This hasn't been mentioned before: the output of the "link" response headers can be controlled by the option export const handle: Handle = async ({ event, resolve }) => {
return await resolve(event, {
preload: ({ type, path }) => type === 'font', // suppress js and css link headers
});
}; See https://kit.svelte.dev/docs/hooks#server-hooks for details. |
Describe the problem
Following #5735 by @benmccann svelte-kit only provides list of scripts to preload in the
link
header. This has several issues:link
headers cause hard-to-debug reverse proxy (e.g.nginx
) errors, see Response Header over 4ko #6790 This is very dangerous as proxy settings may vary between dev / staging / production and the app might unexpectedly explode in production. Moreover, docs and changelog don't detail this behavior.link
header is experimental and only supported in chrome@103+, while<link>
tags work in chrome@66Describe the proposed solution
Since the code to inject
<link rel="modulepreload">
exists for prerendering case anyways (seekit/packages/kit/src/runtime/server/page/render.js
Line 300 in 5e12d3e
<link>
tags can be enabled viasvelte.config.js
option, such asmodulepreload: 'tag' | 'header'
with little added complexity.Alternatives considered
@Rich-Harris suggests removing
link
header altogether (see #6519 (comment) and #6790 (comment)) to fix the issue. My understanding is that it delays preloading altogether, falling back topreload-helper
run instart.js
, which is not optimal.It's also possible to manually convert
link
header to a list of<link>
tags in a middleware, e.g.However, this can't be done in a normal
transformPageChunk
sincelink
header is not available beforeawait resolve
, and involves fully buffering response body, preventing streaming response, which is, again, problematic.Importance
would make my life easier
Additional Information
No response
The text was updated successfully, but these errors were encountered: