From 40b2b0720d83d4bae3afb689941c2162c1a20dec Mon Sep 17 00:00:00 2001 From: Alex Pott Date: Thu, 13 Oct 2016 11:12:04 +0100 Subject: [PATCH] Issue #2481637 by Jelle_S, attiks, mdrummond, Wim Leers: Use src in fallback image --- .../responsive_image/responsive_image.module | 18 +++++++----------- .../Tests/ResponsiveImageFieldDisplayTest.php | 6 +----- 2 files changed, 8 insertions(+), 16 deletions(-) diff --git a/core/modules/responsive_image/responsive_image.module b/core/modules/responsive_image/responsive_image.module index 89ac37f4903..8890dd9f23d 100644 --- a/core/modules/responsive_image/responsive_image.module +++ b/core/modules/responsive_image/responsive_image.module @@ -197,17 +197,13 @@ function template_preprocess_responsive_image(&$variables) { } else { $variables['output_image_tag'] = FALSE; - // Prepare the fallback image. Use srcset in the fallback image to avoid - // unnecessary preloading of images in older browsers. See - // http://scottjehl.github.io/picturefill/#using-picture and - // http://scottjehl.github.io/picturefill/#gotchas for more information. + // Prepare the fallback image. We use the src attribute, which might cause + // double downloads in browsers that don't support the picture tag (might, + // because when picturefill kicks in, it cancels the download and triggers + // the download for the correct image). $variables['img_element'] = array( '#theme' => 'image', - '#srcset' => array( - array( - 'uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()), - ), - ), + '#uri' => _responsive_image_image_style_url($responsive_image_style->getFallbackImageStyle(), $image->getSource()), ); } @@ -265,7 +261,7 @@ function template_preprocess_responsive_image(&$variables) { * * * - * + * * * @endcode * @@ -294,7 +290,7 @@ function template_preprocess_responsive_image(&$variables) { * * * - * + * * * @endcode * This way a browser can decide which tag is preferred based on the diff --git a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php index f5b277dcdf7..aef5ec016e0 100644 --- a/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php +++ b/core/modules/responsive_image/src/Tests/ResponsiveImageFieldDisplayTest.php @@ -315,11 +315,7 @@ class ResponsiveImageFieldDisplayTest extends ImageFieldTestBase { $fallback_image = array( '#theme' => 'image', '#alt' => $alt, - '#srcset' => array( - array( - 'uri' => file_url_transform_relative($large_style->buildUrl($image->getSource())), - ), - ), + '#uri' => file_url_transform_relative($large_style->buildUrl($image->getSource())), ); // The image.html.twig template has a newline after the tag but // responsive-image.html.twig doesn't have one after the fallback image, so