Skip to content

Send preload Link headers from vite_tags - #63

Open
olivier-thatch wants to merge 2 commits into
skryukov:mainfrom
olivier-thatch:vite-tags-link-headers
Open

olivier-thatch wants to merge 2 commits into
skryukov:mainfrom
olivier-thatch:vite-tags-link-headers

Conversation

@olivier-thatch

Copy link
Copy Markdown
Contributor

vite_tags now adds the assets it emits to the response's Link header and sends them as 103 Early Hints, like Rails' javascript_include_tag and stylesheet_link_tag. It follows config.action_view.preload_links_header (on with load_defaults 6.1+), and takes a per-call preload_links_header: that overrides it, with the same name and precedence as Rails 7.1+.

Link: </vite/assets/application-x9y8z7w6.css>; rel=preload; as=style; nopush,</vite/assets/application-a1b2c3d4.js>; rel=modulepreload; as=script; nopush,</vite/assets/vendor-b3c4d5e6.js>; rel=modulepreload; as=script; nopush
  • The links go through Rails' private send_preload_links_header, which writes the header the running Rails version expects: 7.0 joins early hints with newlines under Link, 7.1+ with commas under link. It also stops at 1 KB and skips streamed responses.
  • Stylesheets come first, then entry scripts, then imported chunks, so the 1 KB limit drops the deepest chunks rather than the render-blocking CSS.
  • Each link takes the crossorigin, integrity, and nonce of its tag. With SRI, a stylesheet preload without crossorigin=anonymous would make the browser fetch it twice.
  • Dev mode sends no header.

Apps on load_defaults 6.1+ get the header on upgrade.

@olivier-thatch
olivier-thatch marked this pull request as ready for review November 14, 2026 00:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant