WebP Picture conflict with Lazy Loading
-
Hey guys.
We use our own lazy loading implementation and it is conflicting with your WebP module.
- We use WP filter
wp_get_attachment_image_attributes
to add lazy loading attributes to our images and it is working fine.
- We remove
srcset
andsizes
attributes - We overwrite
src
attribute and add our placeholder to it - We add data attributes for lazy loading script
data-src
,data-srcset
,data-sizes
- You add
srcset
andsizes
attributes without prefix. See the code part(strlen($srcset) ? ' srcset="' . $srcset . '"': '')
here: https://github.com/short-pixel-optimizer/shortpixel-image-optimiser/blob/d0a3629f8452316128f4806afd473be03aeda392/class/front/img-to-picture-webp.php#L300-L305
As result, our lazy loading is not working properly, as images loads on page load from
srcset
attribute.Also, you add
src
attribute with a prefix, but ignore the originalsrc
attribute without prefix, which some lazy loading plugins still use to display placeholders (as ours) or LQIP images.You can see the problem also with Autoptimize plugin.
- Enable Lazy Loading in Autoptimize
- Enable Global Picture tag replacement in your plugin (https://snap.nkdev.info/2020-10-12-1602510118.png)
Result HTML:
Result HTML without WebP:
As you can see, in image tag without your WebP replacements there is an
src
attribute and there are nosrcset
andsizes
attributes.Please, could you look at it and fix it in the next plugin update. We use your plugin for image optimization on our sites and we only need to fix this small problem.
Regards, nK.
- We use WP filter
- The topic ‘WebP Picture conflict with Lazy Loading’ is closed to new replies.