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
Add preload_link_tag helper. #31251
Add preload_link_tag helper. #31251
Conversation
dc81884
to
3cebecb
Compare
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.
Looks good to me @guilleiguaran
|
||
Mime::Type.register "image/png", :png, [], %w(png) | ||
Mime::Type.register "image/jpeg", :jpeg, [], %w(jpg jpeg jpe pjpeg) | ||
Mime::Type.register "image/gif", :gif, [], %w(gif) | ||
Mime::Type.register "image/bmp", :bmp, [], %w(bmp) | ||
Mime::Type.register "image/tiff", :tiff, [], %w(tif tiff) | ||
Mime::Type.register "image/svg+xml", :svg | ||
Mime::Type.register "image/webp", :webp, [], %w(webp) | ||
|
||
Mime::Type.register "audio/mpeg", :mpeg, [], %w(mp1 mp2 mp3) |
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.
I'm curious. Is it safe for the same value to be registered in mine type symbols? This seems to cause warning in the definition of mime method.
https://travis-ci.org/rails/rails/jobs/308298401#L1970
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.
That's right!! I'll remove the video/mpeg
one since it contains old formats.
Are these really common enough as HTTP responses to be in our default set? |
This helper creates a link tag with preload keyword that allows to browser to initiate early fetch of resources. Additionally this send Early Hints if supported. See 59a02fb for more details about Early Hints. Preload spec: https://w3c.github.io/preload/
3cebecb
to
729a3da
Compare
Mime::Type.register "audio/flac", :flac, [], %w(flac) | ||
|
||
Mime::Type.register "video/webm", :webm, [], %w(webm) | ||
Mime::Type.register "video/mp4", :mp4, [], %w(mp4 m4v) |
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.
It seems that mp4
is still duplicated, is this intentional?
https://travis-ci.org/rails/rails/jobs/308761133#L1969
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.
Missed this comment before of merge, will fix it now :/
@matthewd sorry, missed your comment before of merging, probably those types aren't common enough in HTTP responses but I decided to include those in this set because it seems to be the unique way we can lookup the mime types using only the extension. I was planning to leave the
|
My concern about moving from a list of very common files to all "reasonable" files, is that it opens us up to a lot of future churn. And on a very relevant note: it also pretty much obliges us to maintain the values forever. You've removed an existing definition, which will break people's existing applications without a deprecation. We can't do that. I haven't even heard of half of these things, so I'd rather not be stuck keeping them in a list forever, just to support a small number of users (both because of a rare filetype, and a currently rare feature). How about we trim the list for now, and just make the helper raise if we don't know the type? That way people will be forced to either specify it as an option, or register the type for themselves. |
See discussion in #31251
Summary
This helper creates a link tag with preload keyword that allows to the browser to initiate early fetch of resources (different to the specified in
javascript_include_tag
andstylesheet_link_tag
). Additionally, this sends Early Hints if supported.See 59a02fb for more details about Early Hints.
Preload spec: https://w3c.github.io/preload/
Usage examples