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 preload_link_tag work with images #43088

Merged
merged 1 commit into from Aug 24, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
@@ -1,3 +1,7 @@
* `preload_link_tag` properly inserts `as` attributes for files with `image` MIME types, such as JPG or SVG.

*Nate Berkopec*

* Add `weekday_options_for_select` and `weekday_select` helper methods. Also adds `weekday_select` to `FormBuilder`.

*Drew Bragg*, *Dana Kashubeck*, *Kasper Timm Hansen*
Expand Down
4 changes: 1 addition & 3 deletions actionview/lib/action_view/helpers/asset_tag_helper.rb
Expand Up @@ -536,9 +536,7 @@ def resolve_link_as(extname, mime_type)
"style"
elsif extname == "vtt"
"track"
elsif extname == "svg"
"image"
elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font))
elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font image))
type
end
end
Expand Down
3 changes: 2 additions & 1 deletion actionview/test/template/asset_tag_helper_test.rb
Expand Up @@ -255,7 +255,8 @@ def content_security_policy_nonce
%(preload_link_tag '//example.com/font.woff2', crossorigin: 'use-credentials') => %(<link rel="preload" href="//example.com/font.woff2" as="font" type="font/woff2" crossorigin="use-credentials" />),
%(preload_link_tag '/media/audio.ogg', nopush: true) => %(<link rel="preload" href="/media/audio.ogg" as="audio" type="audio/ogg" />),
%(preload_link_tag '/style.css', integrity: 'sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs') => %(<link rel="preload" href="/style.css" as="style" type="text/css" integrity="sha256-AbpHGcgLb+kRsJGnwFEktk7uzpZOCcBY74+YBdrKVGs">),
%(preload_link_tag '/sprite.svg') => %(<link rel="preload" href="/sprite.svg" as="image" type="image/svg+xml">)
%(preload_link_tag '/sprite.svg') => %(<link rel="preload" href="/sprite.svg" as="image" type="image/svg+xml">),
%(preload_link_tag '/mb-icon.png') => %(<link rel="preload" href="/mb-icon.png" as="image" type="image/png">)
}

VideoPathToTag = {
Expand Down