rewrite_images srcset doesn't seem to work

72 views
Skip to first unread message

Damon Edwards

unread,
Sep 17, 2015, 1:25:20 PM9/17/15
to mod-pagespeed-discuss
<img src="//mydomain.com/_cache/29x29x25_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg.pagespeed.ic.s0LHrmVexV.webp" width="29" height="29" alt="BBB" srcset="//mydomain.com/_cache/25_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg 25w, //mydomain.com/_cache/50_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg 50w, //mydomain.com/assets/images/icons/b...@2x.jpg 58w" sizes="(max-width: 767px) 100vw, (max-width: 1024px) 40vw, 33vw" pagespeed_url_hash="3549703635" onload="pagespeed.CriticalImages.checkImageForCriticality(this);">

Given the above as an example output you will notice the image supplied in the src attribute gets the pagespeed treatment but the sources in the srcset attribute aren't touched. Is there a way to enable pagespeed for the sources given in a srcset attribute?

Thanks!

Jeff Kaufman

unread,
Sep 17, 2015, 1:39:09 PM9/17/15
to mod-pagespeed-discuss
Sorry, this isn't something PageSpeed can currently do.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/f972a07b-3d1e-4190-846c-74087f871090%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Damon Edwards

unread,
Sep 17, 2015, 2:20:52 PM9/17/15
to mod-pagespeed-discuss
Is it a planned feature and if so any timeline on availability?


On Thursday, September 17, 2015 at 10:39:09 AM UTC-7, Jeff Kaufman wrote:
Sorry, this isn't something PageSpeed can currently do.

On Thu, Sep 17, 2015 at 1:25 PM, Damon Edwards <dzed...@gmail.com> wrote:
> <img
> src="//mydomain.com/_cache/29x29x25_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg.pagespeed.ic.s0LHrmVexV.webp"
> width="29" height="29" alt="BBB"
> srcset="//mydomain.com/_cache/25_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg 25w,
> //mydomain.com/_cache/50_3e62e1b52b5138d0ee8e5aeeb8ce758b.jpg 50w,
> //mydomain.com/assets/images/icons/b...@2x.jpg 58w" sizes="(max-width: 767px)
> 100vw, (max-width: 1024px) 40vw, 33vw" pagespeed_url_hash="3549703635"
> onload="pagespeed.CriticalImages.checkImageForCriticality(this);">
>
> Given the above as an example output you will notice the image supplied in
> the src attribute gets the pagespeed treatment but the sources in the srcset
> attribute aren't touched. Is there a way to enable pagespeed for the sources
> given in a srcset attribute?
>
> Thanks!
>
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an

Jeff Kaufman

unread,
Sep 17, 2015, 2:27:33 PM9/17/15
to mod-pagespeed-discuss
We have some srcset improvements in trunk that should go out in the
next release, but they're around turning <img src="really big image"
width=a height=b> into <img src="1x-image" srcset="2x-image 2x,
4x-image 4x" width=a height=b>. With those changes PageSpeed will
optimize the srcset urls it generates, but it still won't optimize
existing srcset urls.

The main problem is that PageSpeed understands how to optimize an
attribute that refers to a url, but it doesn't know how to optimize a
piece of an attribute that does that. So with <img src=foo
data-src=bar> we can optimize bar if you tell pagespeed (with
UrlValuedAttribute) that img.data-src refers to an image, but with
srcset="foo 1x, bar 2x" it doesn't (yet) understand that pieces of the
srcset attribute can be individually optimized.

This is definitely something we'd like pagespeed to handle, and if you
or anyone else is interested in working on this we'd love the help!
>> > email to mod-pagespeed-di...@googlegroups.com.
> --
> You received this message because you are subscribed to the Google Groups
> "mod-pagespeed-discuss" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to mod-pagespeed-di...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/e6911643-2c15-473a-b7c9-1b4467a79ed8%40googlegroups.com.

Damon Edwards

unread,
Sep 24, 2015, 5:12:30 PM9/24/15
to mod-pagesp...@googlegroups.com
here you go :)

<img src="29.jpg" width="29" height="29" srcset="25.jpg 25w, 50.jpg 50w, main.jpg 58w" sizes="(max-width: 767px) 100vw, (max-width: 1024px) 40vw, 33vw">

// current
src_image = image.attribute('src');
src_image = doModPagespeedMagicalness(src_image);
image.attribute('src', src_image);
// add srcset
srcset_images = image.attribute('srcset');
if(srcset_images != null) {
srcset_images = srcset_images.split(','); // U+002C COMMA character
each(srcset_images, function(index, srcset) {
srcset_url = extractUrlFromImageCandidateString(srcset);
srcset_url_pagespeed = doModPagespeedMagicalness(srcset_url);
srcset_images[index] = srcset.replace(srcset_url, srcset_url_pagespeed);
});
srcset_images = implode(', ', srcset_images); // U+002C COMMA character + space character to satisfy "If an image candidate string contains no descriptors 
 // and no space characters after the URL, the following image candidate string, if there is one, must begin
 // with one or more space characters."
};
image.attribute('srcset', srcset_images);

<img src="29.jpg.pagespeed.XX.XXXXXXX.webp" width="29" height="29" srcset="25.jpg.pagespeed.XX.XXXXXXX.webp 25w,  50.jpg.pagespeed.XX.XXXXXXX.webp 50w,  main.jpg.pagespeed.XX.XXXXXXX.webp 58w" sizes="(max-width: 767px) 100vw, (max-width: 1024px) 40vw, 33vw">

Boom, done, next assignment :)


For more options, visit https://groups.google.com/d/optout.



--
Damon Edwards

Jeff Kaufman

unread,
Sep 25, 2015, 8:54:27 AM9/25/15
to mod-pagespeed-discuss
Yeah, it would be nice if it were that easy!

doModPagespeedMagicalness really is "function
doModPagespeedMagicalness(url, callback)" (because it needs to talk to
the cache and is willing to wait up to 10ms for optimizations to run
in the background) among other things.
> https://groups.google.com/d/msgid/mod-pagespeed-discuss/CAHJN-tmx1HtR%3DtmUg5p9SBFK90u_bq%2B-w23r7szuVsKJQRRK3A%40mail.gmail.com.
Reply all
Reply to author
Forward
0 new messages