Skip to content
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

Make it possible to opt-out of sending Link header in preload_link_tag #51441

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

stanhu
Copy link
Contributor

@stanhu stanhu commented Mar 28, 2024

This commit adds a preload_links_header option to preload_link_tag to disable sending of the Link header in the HTTP response.

Currently ActionView::Helpers::AssetTagHelper.preload_links_header only controls whether javascript_include_tag and stylesheet_link_tag send the Link header, but there is no way to control the behavior of preload_link_tag. We could just check that variable, but existing applications might be relying on preload_link_tag to add the header. Users also might want control over this on a per call basis.

Closes #51436

Before submitting the PR make sure the following are checked:

  • This Pull Request is related to one change. Unrelated changes should be opened in separate PRs.
  • Commit message has a detailed description of what changed and why. If this PR fixes a related issue include it in the commit message. Ex: [Fix #issue-number]
  • Tests are added or updated if you fix a bug or add a feature.
  • CHANGELOG files are updated for the changed libraries if there is a behavior change or additional feature. Minor bug fixes and documentation changes should not be included.

@rails-bot rails-bot bot added the actionview label Mar 28, 2024
@stanhu stanhu force-pushed the sh-opt-out-link-header-preload-link-tag branch from d3e506a to 662584f Compare March 28, 2024 19:20
@stanhu stanhu force-pushed the sh-opt-out-link-header-preload-link-tag branch from 662584f to 4e94e69 Compare March 28, 2024 21:01
This commit adds a `preload_links_header` option to `preload_link_tag`
to disable sending of the Link header in the HTTP response.

Currently `ActionView::Helpers::AssetTagHelper.preload_links_header`
only controls whether `javascript_include_tag` and
`stylesheet_link_tag` send the Link header, but there is no way to
control the behavior of `preload_link_tag`. We could just check that
variable, but existing applications might be relying on
`preload_link_tag` to add the header. Users also might want control
over this on a per call basis.

Closes rails#51436
@stanhu stanhu force-pushed the sh-opt-out-link-header-preload-link-tag branch from 4e94e69 to 6578fbf Compare March 28, 2024 21:03
@@ -357,25 +357,26 @@ def preload_link_tag(source, options = {})
crossorigin = "anonymous" if crossorigin == true || (crossorigin.blank? && as_type == "font")
integrity = options[:integrity]
nopush = options.delete(:nopush) || false
send_link_header = options.key?(:preload_links_header) ? options.delete(:preload_links_header) : true
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think early_hint: false would be a better name for this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Disable send_preload_links_header outright
3 participants