aFarkas / wp-lazysizes

Brings lazySizes.js to WordPress
GNU General Public License v2.0
64 stars 17 forks source link

Should this plugin be changed to disable WP native responsive images? #16

Closed joeldbirch closed 8 years ago

joeldbirch commented 8 years ago

Hello,

In light of issue #11, maybe this plugin should disable WordPress's native responsive images, allowing LazySizes to work as normal? I find the native implementation can be a hit and miss affair anyway, particularly on sites built prior to its existence. Here is an example <img> output on a random site I built, formatted for readability:

<img
    class="alignleft wp-image-6312 "
    src="http://site.dev/wp-content/uploads/2016/04/the-image-200x300.jpg"
    alt="the image"
    width="171"
    height="257"
    srcset="
        http://site.dev/wp-content/uploads/2016/04/the-image-200x300.jpg 200w,
        http://site.dev/wp-content/uploads/2016/04/the-image-768x1152.jpg 768w,
        http://site.dev/wp-content/uploads/2016/04/the-image-683x1024.jpg 683w,
        http://site.dev/wp-content/uploads/2016/04/the-image.jpg 800w"
    sizes="(max-width: 171px) 100vw, 171px">

I don't think that combination of attributes and image sizes delivers particularly useful benefits, and I find this quite common. I think users of wp-lazysizes will likely benefit more from disabling this new markup and continue lazy-loading a suitable image size.

I have been using the following code from Joseph Fusco's Disable Responsive Images plugin to disable the native responsive images markup, which makes wp-lazyloading work correctly:

add_filter( 'max_srcset_image_width', create_function( '', 'return 1;' ) );

Do you think wp-lazysizes should add this so lazyloading continues to work as normal, without the more verbose markup?

I've been familiarising myself with this plugin's code, doing some refactoring and adding tests, so I thought I'd ask for direction here before I go much further.

joeldbirch commented 8 years ago

As is often the case, soon after posting this I noticed that wp-lazysizes does intend to use WordPress's native srcset attribute (changing it to data-srcset). I probably wouldn't have bothered asking the above had I noticed. The way forward is probably to resolve issue #11 for now.

Feel free to close this if I've answered my own question. ;)

szepeviktor commented 8 years ago

All right.