Skip to content

Commit

Permalink
Merge pull request #43088 from nateberkopec/preload-images
Browse files Browse the repository at this point in the history
Make preload_link_tag work with images
  • Loading branch information
byroot committed Aug 24, 2021
2 parents d2b23f4 + 46bfd08 commit c7647f8
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 4 additions & 0 deletions actionview/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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

0 comments on commit c7647f8

Please sign in to comment.