Skip to content

Commit c7647f8

Browse files
authored
Merge pull request rails#43088 from nateberkopec/preload-images
Make preload_link_tag work with images
2 parents d2b23f4 + 46bfd08 commit c7647f8

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

actionview/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
* `preload_link_tag` properly inserts `as` attributes for files with `image` MIME types, such as JPG or SVG.
2+
3+
*Nate Berkopec*
4+
15
* Add `weekday_options_for_select` and `weekday_select` helper methods. Also adds `weekday_select` to `FormBuilder`.
26

37
*Drew Bragg*, *Dana Kashubeck*, *Kasper Timm Hansen*

actionview/lib/action_view/helpers/asset_tag_helper.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -536,9 +536,7 @@ def resolve_link_as(extname, mime_type)
536536
"style"
537537
elsif extname == "vtt"
538538
"track"
539-
elsif extname == "svg"
540-
"image"
541-
elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font))
539+
elsif (type = mime_type.to_s.split("/")[0]) && type.in?(%w(audio video font image))
542540
type
543541
end
544542
end

actionview/test/template/asset_tag_helper_test.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -255,7 +255,8 @@ def content_security_policy_nonce
255255
%(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" />),
256256
%(preload_link_tag '/media/audio.ogg', nopush: true) => %(<link rel="preload" href="/media/audio.ogg" as="audio" type="audio/ogg" />),
257257
%(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">),
258-
%(preload_link_tag '/sprite.svg') => %(<link rel="preload" href="/sprite.svg" as="image" type="image/svg+xml">)
258+
%(preload_link_tag '/sprite.svg') => %(<link rel="preload" href="/sprite.svg" as="image" type="image/svg+xml">),
259+
%(preload_link_tag '/mb-icon.png') => %(<link rel="preload" href="/mb-icon.png" as="image" type="image/png">)
259260
}
260261

261262
VideoPathToTag = {

0 commit comments

Comments
 (0)