I think the gist you posted don´t work. Why? Maybe image has srcset and data-srcset at the same time. I´m thinking on how lasizes work. Lazysizes can use a srcset with a placeholder image and a data-srcset whit the whole set of images. In your gist, rewrites srcset or data-srcset , if i´m not wrong, cause the if don´t iterate trougth the attributes.
But i have made other change to the file, suppress the if (element.... and include these to the loop above it, this cover the data-srcset and the amp-img src image issue that is related at ##1413 issue in incubator-pagespeed-mod. I will try to make a PR. On 2019/06/14 14:19:04, Otto van der Schaaf <[email protected]> wrote: > I think that what you did there is functionally correct, but it could be > condensed to something like: > https://gist.github.com/oschaaf/ce4f332ef64cc85371e38f47992ffadf > > Should this new handling of kDataSrcset be default behavior? Or should it > be an opt-in feature? > Would it be possible to create a pull request with that change? > > Otto > > > On Thu, Jun 13, 2019 at 8:45 PM Longinos Ferrando <[email protected]> wrote: > > > Hi to all > > As @oschaaf seguested I send this to the dev list. > > Digiing in the code I found that in > > archive net/instaweb/rewriter/image_rewrite_filter.cc lines 2141 - 2146 > > have a if statement to test HtmlName::kImg and a test to check if > > HtmlName::kSrcset > > is present. > > This make that other attributes like data-srcset can´t be > > rewrited/optimized by pagespeed. > > I make a test, and it is working getting data-srcset optimized. > > 1.- Insert kDataSrcset, in pagespeed/kernel/html/html_name.h as line 105 > > 2.- Insert "data-srcset", HtmlName::kDataSrcset > > in pagespeed/kernel/html/html_name.gperf as line 129 > > 3.- Chenged lines 2141-22146 in the file > > net/instaweb/rewriter/image_rewrite_filter.cc > > lines with > > > > 2141 if (element->keyword() == HtmlName::kImg) { > > HtmlElement::Attribute* srcset = > > element->FindAttribute(HtmlName::kSrcset); > > HtmlElement::Attribute* datasrcset = > > element->FindAttribute(HtmlName::kDataSrcset); > > if (srcset != nullptr) { > > BeginRewriteSrcSet(element, srcset); > > } > > if (datasrcset != nullptr) { > > srcset = datasrcset ; > > BeginRewriteSrcSet(element, srcset); > > } > > > > } > > > > This work, data-srcset attributes are rewrited/optimized, but for sure is > > not the best way to do as far as i not a developer. > > > > Any thougths? > > > > Thx in advance > > >
