-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
feat: supports link header #4785
Conversation
|
I wonder if we should not include the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks — is there any reason we wouldn't just always include this header? Would be simpler if we didn't have to introduce another config option here
Thanks for that one @Rich-Harris I have updated the PR — and you're right, I cannot see why this header SHOULD not have been included by default. Have added that in. As per other points mentioned around what do we do for pre-rended files, do we need something similar to this by in lastmile? Aka post process once that file is either read from disk, from KV or so forth? |
This PR doesn't actually implement early hints as discussed in the linked issue (e.g. nowhere are we returning a 103 status code). What this PR does do is implement headers for server push is which is being removed from browsers. I don't think this PR would necessarily hurt, but I think the benefits are likely to be minimal. The benefits might be meaningful for a page with high SSR render time if early hints were indeed implemented From https://medium.com/reloading/preload-prefetch-and-priorities-in-chrome-776165961bbf:
From https://www.ctrl.blog/entry/http2-push-chromium-deprecation.html:
From https://brianli.com/2020/12/chrome-to-drop-support-for-http2-server-push/:
|
Sorry to have caused you trouble. |
@maraisr Thank you for investigating this. I believe this PR could still move forward (although possibly with changes). I think there's some miscommunication at play here. Hints can be added both to Now for the kicker: Since we already have Apart from the But would adding this to SSR now become a chore later if we decide to move the responsibility to adapters (as noted in OP)? |
I think we should reopen this PR until we've discussed this further, but I'm unable to do so - @maraisr can you hit the reopen button please? Thanks 🙏 |
Some further relevant discussion about flushing JS/CSS-related tags (basically everything in Also related: #4158 (comment) |
Since early headers would require solving the bigger streaming questions (early status codes) it sounds like it could continue to be discussed in #4831, and for now we just focus on improvements assuming late headers. In that case, this seems mostly there as a stop-gap, except for the adapter-specific questions. Or should we focus on the full streaming solution? Regarding the adapters, do you have opinions on where to take the adapter api in order to expose this sort of per-page information? For instance, it'd be nice if they were able to setup their platform's necessary plumbing to add the headers to prerendered pages. |
Ah, I wasn't aware of that. Thanks for sharing. Although, it sounds like the impact is quite limited when the page has been cached and the early hint may not be sent at all: "Early Hints may be emitted less frequently on requests where the content is cacheable. Cloudflare CDN is more likely to retrieve a response header before the asynchronous Early Hints lookup finishes if the response has been cached. Cloudflare will not send a 103 response if the main response header is already available."
I think I'd lean towards this so that all the browsers work the same. Most testing and development is probably done in Chrome, so it probably makes sense to have the other browsers work the same way.
I don't think this would really make sense to live in adapters since it's a runtime rather than build-time concern? |
Yeah, that's expected. When a page is cached it makes sense not to use early hints since they wouldn't be early as they wouldn't be waiting for origin. But since this is regarding SSRed pages, most won't be cached. And iirc Cloudflare also doesn't cache html pages by default even with
I wasn't clear there, but this is a concern when prerendering pages. Granted, the upside is limited for the same reason as Cloudflare won't use early hints when cached, but this is something that'd impact other headers anyway, so it's worth considering how it'd be handled anyway. We currently have no way to specify headers on prerendered pages outside of meta tags. e: Come to think of it, this would probably be doable for all headers as-is, right? We wouldn't need a separate api for SSR to specify additional data; whatever headers are in the response could be passed on to the adapter to deal with. |
Please don't delete this checklist! Before submitting the PR, please make sure you do the following:
Tests
pnpm test
and lint the project withpnpm lint
andpnpm check
Changesets
pnpx changeset
and following the prompts. All changesets should bepatch
until SvelteKit 1.0This is my attempt at solving #4783 albeit not specifically for Cloudflare, but think all servers could benefit from it.
Probably this PR won't be solution that'll land as only SSR'd non-preloaded pages will have this header. But really all static html files could use it.
So, my thinking lies more about exposing the assets consumed by a page to an adaptor.
Adaptors know how to deal with their targets, as some use a
_headers
file, others allow it as well asnew Response('', {headers})
, and other are entirely different. So maybe instead of this functionality being first-class, defer it to an adaptor.This way Cloudflare's adaptor can build a
_headers
file to contain the headers for all static (pre-rendered) html files, as well as include theLink
header for ssr responses.Will mark PR as draft, but feel free to open and merge if you see fit.