-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Add preload_link_tag helper #1874
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
Comments
My own versions of helpers for this: (for def javascript_entrypoint_pack_preload_tag(*names, **options)
actual_paths = javascript_entrypoint_pack_paths(*names)
# rubocop:disable Rails/OutputSafety
actual_paths.uniq.map do |actual_path|
href = actual_path
tag_options = {
rel: "preload",
href: href,
as: "script",
}.reverse_merge(options)
tag(
:link,
tag_options,
)
end.join("\n").html_safe
# rubocop:enable Rails/OutputSafety
end
def javascript_entrypoint_pack_paths(*names)
logical_paths = sources_from_manifest_entrypoints(names, type: :javascript)
logical_paths.uniq.map do |logical_path|
path_to_javascript(logical_path, skip_pipeline: true)
end
end |
I did it, I will create a PR in the afternoon 👍 |
I left feedback about this over here: #2124 (review) Apart from that, I feel like there is some de-sync happening between all of us. Let me try and straighten it out:
This is useful for preloading fonts, videos, and web workers, but preloading all of your JS scripts is antithetical to progressive web enhancement and chunk lazy loading. Plus, webpack gives you this as a feature.
In the google link:
Mozilla does not currently support this at all:
This is my main source of confusion. You don't want to preload the css, you want to preload the fonts and images inside the css so that fonts, css, and images can all be downloaded in parallel instead of waiting for the browser to parse the css.
The initial question was about stylesheet assets. While your approach is completely valid, I am not sure it makes for a good general recommendation to preload all chunks like this. I would instead let webpack inject the Webpack docs on preloading: https://webpack.js.org/guides/code-splitting/#prefetchingpreloading-modules |
Good to close? |
Looks good to me |
|
@infernalmaster What are you trying to achieve ? You probably don't want/need to preload you |
Rails recently released support for preloading content:
rails/rails#31251
Documented here: https://api.rubyonrails.org/classes/ActionView/Helpers/AssetTagHelper.html#method-i-preload_link_tag
Which is recommended by Google and Mozilla to speed up pageloading performance:
https://developers.google.com/web/fundamentals/performance/resource-prioritization
https://developer.mozilla.org/en-US/docs/Web/HTML/Preloading_content
Any chance we could get similar support for "stylesheet_pack_tag" et al?
The text was updated successfully, but these errors were encountered: