Follow up for #1883526: Decide on the picture polyfill to use

Problem/Motivation

If you don't want to output an image on for instance mobile phones, you now need to use display:none; to hide it, but there's still a request for the specified image.

Proposed resolution

The Drupal 7 version of the picture module has an option to map a breakpoint to an empty image. If you select this option the image source is replaced by 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7'. So it adds like 50 bytes to the request, but it will not fire a new HTTP request.

Remaining tasks

  1. Decide if we want this
  2. Write a patch
  3. Test

User interface changes

A new option is added on admin/settings/picture/group

API changes

None

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Wim Leers’s picture

Priority: Normal » Major

This has the potential to have massive, huge, epic performance impact for Drupal on mobile devices. Many saved requests, kilobytes or even megabytes… means that this patch can potentially bring a site from loading in 20 seconds on a mobile device to 2 seconds. It depends on the site of course.

Increasing priority — even though that's likely to be contentious. This issue deserves more attention.

iwuv’s picture

Pretty sweet, huh. Attiks is the man.

Back in March, I presented this base64 empty image idea to him and by the next day it was in 7.x-dev. Tested it and worked perfectly from the start. I'd be more than happy to test it on D8 if it gets patched in.

On mobile, there are times when certain images are just not necessary and using this method saves an http request as well as the image download. I've used this method in production and it does work as you'd imagine for increasing performance.

I'm sure the front-end geniuses will come up with an answer on whether or not there's a better way to handle this.

attiks’s picture

#2 Thanks for the idea and your help on D7 version.

I had a quick word with Morten and there's definitely a need for this in Drupal 8.

I'll roll a patch later today/tomorrow

nod_’s picture

+1 to that as well.

attiks’s picture

Status: Active » Needs review
FileSize
12.1 KB

Combined patch so people can test this, this patch also contains the one from #1883526: Decide on the picture polyfill to use

Status: Needs review » Needs work
Issue tags: -Usability, -mobile, -revisit before beta, -frontend performance, -media queries, -Responsive Design, -Design Initiative, -d8mux

The last submitted patch, i1999312-5.patch, failed testing.

attiks’s picture

Status: Needs work » Needs review
Issue tags: +Usability, +mobile, +revisit before beta, +frontend performance, +media queries, +Responsive Design, +Design Initiative, +d8mux

#5: i1999312-5.patch queued for re-testing.

attiks’s picture

Issue tags: +Needs manual testing

Tagging

evanmwillhite’s picture

Patch applied fine. Added picture mapping for 1x mobile and 1x narrow and large image style for 1x wide. Image replacement occurred with no issues/console errors. (see screenshots). Tested in Chrome/Firefox on Mac

attiks’s picture

#9 Thank you

xjm’s picture

Issue tags: -Needs manual testing
iwuv’s picture

Status: Needs review » Needs work
Issue tags: +Usability, +mobile, +revisit before beta, +frontend performance, +media queries, +Responsive Design, +Design Initiative, +d8mux

The last submitted patch, i1999312-5.patch, failed testing.

catch’s picture

Category: feature » task

Nice idea. Not really a feature, this is a straight performance improvement.

RainbowArray’s picture

Does this need a reroll?

MustangGB’s picture

After seeing #9 could someone clarify if the display:none; CSS code remains, or is it removed in favour of displaying a 1px x 1px empty image?

If it remains then good.

But if it is removed then not so good because this is more the expected behaviour of visibility:hidden; rather than display:none;.

botanic_spark’s picture

Issue summary: View changes
Status: Needs work » Needs review
FileSize
3.36 KB

Modification of the patch #5.
Modification of the image_cache functions.

I also saw that in patch #5 picture tag was converted to span. Not sure why this was done, but i used the picture tag in this patch.

RainbowArray’s picture

Status: Needs review » Needs work

We should be using span elements, not picture elements. The picture element has not yet been standardized and implemented in browsers. It looks highly likely that will happen, but at this point we should be using a polyfill based on spans rather than picture elements. Otherwise if the picture element changes, then we have code written against the old version of the standard, which is bad.

As the issue linked in #5 explains, if picture is standardized and implemented prior to d8 launch, we can switch to the picture element. Otherwise that's a switch that could be considered for 8.1 or beyond.

catch’s picture

Issue tags: -revisit before beta

Removing 'revisit' tag - could happen any time I think?

attiks’s picture

Issue tags: +Needs reroll

FYI: picture is renamed to responsive_image so this needs a reroll once #2124377-74: Rename "Picture" module to "Responsive Image" module is committed

lokapujya’s picture

Status: Needs work » Needs review
Issue tags: -Needs reroll
FileSize
3.68 KB

Rerolled. Renamed the define and _picture_image_style_url() to _responsive_image_image_style_url().

Status: Needs review » Needs work

The last submitted patch, 21: 1999312-21.patch, failed testing.

lokapujya’s picture

Status: Needs work » Needs review

21: 1999312-21.patch queued for re-testing.

attiks’s picture

Status: Needs review » Reviewed & tested by the community

Nice job!

tim.plunkett’s picture

Title: Add an 'empty image' option for picture » Add an 'empty image' option for responsive image
Status: Reviewed & tested by the community » Needs work
  1. +++ b/core/modules/responsive_image/lib/Drupal/responsive_image/ResponsiveImageMappingFormController.php
    @@ -71,6 +71,7 @@ public function form(array $form, array &$form_state) {
    +    $image_styles[RESPONSIVE_IMAGE_EMPTY_IMAGE] = t('- empty image -');
    

    $this->t()

  2. +++ b/core/modules/responsive_image/responsive_image.module
    @@ -8,6 +8,8 @@
    +define('RESPONSIVE_IMAGE_EMPTY_IMAGE', '_empty image_');
    

    Why are we using define() and not const?

  3. +++ b/core/modules/responsive_image/responsive_image.module
    @@ -353,7 +355,25 @@ function responsive_image_get_image_dimensions($variables) {
    +    return 'data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7';
    

    This could probably use a comment.

Eli-T’s picture

Component: picture.module » responsive_image.module
baisong’s picture

Re-rolled patch with tim.plunket's feedback incorporated

baisong’s picture

Status: Needs work » Needs review
attiks’s picture

Status: Needs review » Reviewed & tested by the community

Looks good to me

Dries’s picture

Status: Reviewed & tested by the community » Fixed

Committed to 8.x. Thank you.

  • Dries committed 4cfb1d8 on 8.x
    Issue #1999312 by baisong, lokapujya, botanic_spark, attiks: Add an '...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.