Merge pull request #43088 from nateberkopec/preload-images

Make preload_link_tag work with images
This commit is contained in:
Jean Boussier 2021-08-24 22:14:21 +02:00 committed by GitHub
commit c7647f8842
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

@ -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*

@ -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

@ -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 = {