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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure preload_link_tag preloads modules correctly #44198

Merged
merged 1 commit into from Jan 20, 2022

Conversation

ElMassimo
Copy link
Contributor

@ElMassimo ElMassimo commented Jan 18, 2022

Summary

This pull request fixes preload_link_tag to support preloading of module scripts.

When type: 'module' is provided, it will now use rel: 'modulepreload' instead of rel: 'preload'.

Background 馃摐

Previously, both the rendered tag and the early response hint sent in preload_link_tag were using rel=preload for all scripts, including module scripts.

Browsers will ignore the pre-loaded resource because the types don't match (preloaded a script, but included a module).

Screenshots 馃摲

Screen Shot 2021-03-18 at 16 12 12

References 馃敆

Prior to this change, preload_link_tag always used rel=preload

This causes the browser to make a request to preload the script, but
for modules scripts the rel does not match the type, so the browser
can not reuse the prefetched script and discards it.

When passing type="module", it should use rel=modulepreload instead.

[0] developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
[1] developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Link
[2] developer.mozilla.org/en-US/docs/Web/HTML/Link_types/modulepreload
[3] developers.google.com/web/updates/2017/12/modulepreload
@rails-bot rails-bot bot added the actionview label Jan 18, 2022
@rafaelfranca rafaelfranca merged commit c777afb into rails:main Jan 20, 2022
rafaelfranca added a commit that referenced this pull request Jan 20, 2022
Ensure preload_link_tag preloads modules correctly
@ElMassimo ElMassimo deleted the preload-modules branch January 20, 2022 02:29
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.

None yet

2 participants