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
- Decide if we want this
- Write a patch
- Test
User interface changes
A new option is added on admin/settings/picture/group
API changes
None
Comment | File | Size | Author |
---|---|---|---|
#27 | responsive_image-empty_option-1999312-27.patch | 3.74 KB | baisong |
#21 | 1999312-21.patch | 3.68 KB | lokapujya |
#17 | picture-1999312-17.patch | 3.36 KB | botanic_spark |
#9 | Screen Shot 2013-05-24 at 1.13.00 PM.png | 131.52 KB | evanmwillhite |
#9 | Screen Shot 2013-05-24 at 1.13.16 PM.png | 50.38 KB | evanmwillhite |
Comments
Comment #1
Wim LeersThis 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.
Comment #2
iwuv CreditAttribution: iwuv commentedPretty 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.
Comment #3
attiks CreditAttribution: attiks commented#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
Comment #4
nod_+1 to that as well.
Comment #5
attiks CreditAttribution: attiks commentedCombined patch so people can test this, this patch also contains the one from #1883526: Decide on the picture polyfill to use
Comment #7
attiks CreditAttribution: attiks commented#5: i1999312-5.patch queued for re-testing.
Comment #8
attiks CreditAttribution: attiks commentedTagging
Comment #9
evanmwillhite CreditAttribution: evanmwillhite commentedPatch 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
Comment #10
attiks CreditAttribution: attiks commented#9 Thank you
Comment #11
xjmComment #12
iwuv CreditAttribution: iwuv commented#5: i1999312-5.patch queued for re-testing.
Comment #14
catchNice idea. Not really a feature, this is a straight performance improvement.
Comment #15
RainbowArrayDoes this need a reroll?
Comment #16
MustangGB CreditAttribution: MustangGB commentedAfter 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 thandisplay:none;
.Comment #17
botanic_spark CreditAttribution: botanic_spark commentedModification 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.
Comment #18
RainbowArrayWe 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.
Comment #19
catchRemoving 'revisit' tag - could happen any time I think?
Comment #20
attiks CreditAttribution: attiks commentedFYI: picture is renamed to responsive_image so this needs a reroll once #2124377-74: Rename "Picture" module to "Responsive Image" module is committed
Comment #21
lokapujyaRerolled. Renamed the define and _picture_image_style_url() to _responsive_image_image_style_url().
Comment #23
lokapujya21: 1999312-21.patch queued for re-testing.
Comment #24
attiks CreditAttribution: attiks commentedNice job!
Comment #25
tim.plunkett$this->t()
Why are we using define() and not const?
This could probably use a comment.
Comment #26
Eli-TComment #27
baisongRe-rolled patch with tim.plunket's feedback incorporated
Comment #28
baisongComment #29
attiks CreditAttribution: attiks commentedLooks good to me
Comment #30
Dries CreditAttribution: Dries commentedCommitted to 8.x. Thank you.