Skip to content
Snippets Groups Projects
Commit 40b2b072 authored by Alex Pott's avatar Alex Pott
Browse files

Issue #2481637 by Jelle_S, attiks, mdrummond, Wim Leers: Use src in fallback image

parent b09f9222
No related branches found
No related tags found
No related merge requests found
...@@ -197,17 +197,13 @@ function template_preprocess_responsive_image(&$variables) { ...@@ -197,17 +197,13 @@ function template_preprocess_responsive_image(&$variables) {
} }
else { else {
$variables['output_image_tag'] = FALSE; $variables['output_image_tag'] = FALSE;
// Prepare the fallback image. Use srcset in the fallback image to avoid // Prepare the fallback image. We use the src attribute, which might cause
// unnecessary preloading of images in older browsers. See // double downloads in browsers that don't support the picture tag (might,
// http://scottjehl.github.io/picturefill/#using-picture and // because when picturefill kicks in, it cancels the download and triggers
// http://scottjehl.github.io/picturefill/#gotchas for more information. // the download for the correct image).
$variables['img_element'] = array( $variables['img_element'] = array(
'#theme' => 'image', '#theme' => 'image',
'#srcset' => array( '#uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
array(
'uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()),
),
),
); );
} }
...@@ -265,7 +261,7 @@ function template_preprocess_responsive_image(&$variables) { ...@@ -265,7 +261,7 @@ function template_preprocess_responsive_image(&$variables) {
* <picture> * <picture>
* <source media="(min-width: 0px)" srcset="sites/default/files/styles/thumbnail/image.jpeg" /> * <source media="(min-width: 0px)" srcset="sites/default/files/styles/thumbnail/image.jpeg" />
* <source media="(min-width: 560px)" sizes="(min-width: 700px) 700px, 100vw" srcset="sites/default/files/styles/large/image.jpeg 480w, sites/default/files/styles/medium/image.jpeg 220w" /> * <source media="(min-width: 560px)" sizes="(min-width: 700px) 700px, 100vw" srcset="sites/default/files/styles/large/image.jpeg 480w, sites/default/files/styles/medium/image.jpeg 220w" />
* <img srcset="fallback.jpeg" /> * <img src="fallback.jpeg" />
* </picture> * </picture>
* @endcode * @endcode
* *
...@@ -294,7 +290,7 @@ function template_preprocess_responsive_image(&$variables) { ...@@ -294,7 +290,7 @@ function template_preprocess_responsive_image(&$variables) {
* <picture> * <picture>
* <source [...] mime-type="image/webp" srcset="image1.webp 1x, image2.webp 2x, image3.webp 3x"/> * <source [...] mime-type="image/webp" srcset="image1.webp 1x, image2.webp 2x, image3.webp 3x"/>
* <source [...] mime-type="image/jpeg" srcset="image1.jpeg 1x, image2.jpeg 2x, image3.jpeg 3x"/> * <source [...] mime-type="image/jpeg" srcset="image1.jpeg 1x, image2.jpeg 2x, image3.jpeg 3x"/>
* <img srcset="fallback.jpeg" /> * <img src="fallback.jpeg" />
* </picture> * </picture>
* @endcode * @endcode
* This way a browser can decide which <source> tag is preferred based on the * This way a browser can decide which <source> tag is preferred based on the
......
...@@ -315,11 +315,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles = ...@@ -315,11 +315,7 @@ protected function doTestResponsiveImageFieldFormatters($scheme, $empty_styles =
$fallback_image = array( $fallback_image = array(
'#theme' => 'image', '#theme' => 'image',
'#alt' => $alt, '#alt' => $alt,
'#srcset' => array( '#uri' => file_url_transform_relative($large_style->buildUrl($image->getSource())),
array(
'uri' => file_url_transform_relative($large_style->buildUrl($image->getSource())),
),
),
); );
// The image.html.twig template has a newline after the <img> tag but // The image.html.twig template has a newline after the <img> tag but
// responsive-image.html.twig doesn't have one after the fallback image, so // responsive-image.html.twig doesn't have one after the fallback image, so
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment