apache / incubator-pagespeed-mod

Apache module for rewriting web pages to reduce latency and bandwidth.
http://modpagespeed.com
Apache License 2.0
696 stars 158 forks source link

Can't convert to webp except on image tags #1239

Open jeffkaufman opened 8 years ago

jeffkaufman commented 8 years ago

With UrlValuedAttribute you can tell pagespeed about other attributes but it won't turn them into webp unless they're on an img tag:

    pagespeed UrlValuedAttribute img data-src image; # yes webp

    pagespeed UrlValuedAttribute a href image; # no webp
    pagespeed UrlValuedAttribute a data-src image; # no webp
    pagespeed UrlValuedAttribute custom src image; # no webp
    pagespeed UrlValuedAttribute custom href image; # no webp
    pagespeed UrlValuedAttribute custom data-src image; # no webp

See this demo page: http://www.jefftk.com/uva--a-href-image

Reported on the mailing list: https://groups.google.com/d/msgid/mod-pagespeed-discuss/CAD%2Biv0wXSwQ4MenawEz_3X0f1w5sxzQxLQOAUyw5__YYMucT_w%40mail.gmail.com?utm_medium=email&utm_source=footer

jeffkaufman commented 8 years ago

@huibaolin Can you think of any reason this would happen?

huibaolin commented 8 years ago

There are 2 issues in the HTML: http://www.jefftk.com/uva--a-href-image

  1. "custom" tag is not closed
  2. <img> is embedded inside <a> tag.

The illustrate, the HTML looks like

<a ... ><img ...></a><custom ...>

Images inside <a> and <custom> are not rewritten. They are just cache extended. Only the images inside <img> have been optimized.

Changing the HTML to the following makes all image optimized:

<a ...></a><img ...><custom ...></custom>

We don't rewrite images in an element (<a> tag here) if it has any child (<img> here) which might be in flush window.

jeffkaufman commented 8 years ago

@huibaolin Thanks for catching that! It sounds like the problem is that we don't rewrite image attributes of tags that have children? Why not? Can't we rewrite the <a ... when we get to the >?

huibaolin commented 8 years ago

Yes, we don't rewrite attributes (image & css) if a tag has children and the children might be in a different flush window. I think the problem is because we can't propagate up correctly. @morlovich might have more details.