splide icon indicating copy to clipboard operation
splide copied to clipboard

Lazy loading not setting srcset attribute

Open tonyastley opened this issue 6 years ago • 5 comments

The following mark-up only creates a src attribute for the image, and doesn't create a srcset:

<img
    data-splide-lazy-srcset="/assets/img//banners/image-w360.jpg 360w, /assets/img//banners/image-w768.jpg 768w, /assets/img//banners/image-w960.jpg 960w, /assets/img//banners/image-w1200.jpg 1200w, /assets/img//banners/image-w2000.jpg 2000w" sizes="80vw" 
    data-splide-lazy="/assets/img//banners/image-w1200.jpg" 
    alt="Making buying flooring pleasurable" 
    class="desktopBanner" 
>

The above results in the following (src is created but no srcset, causing it to load only the 1200px:

<img
    data-splide-lazy-srcset="/assets/img//banners/image-w360.jpg 360w, /assets/img//banners/image-w768.jpg 768w, /assets/img//banners/image-w960.jpg 960w, /assets/img//banners/image-w1200.jpg 1200w, /assets/img//banners/image-w2000.jpg 2000w" sizes="80vw" 
    data-splide-lazy="/assets/img//banners/image-w1200.jpg" 
    alt="Making buying flooring pleasurable" 
    class="desktopBanner" 
    src="/assets/img//banners/image-w1200.jpg" style=""
>

tonyastley avatar Oct 26 '20 08:10 tonyastley

Try it with this branch https://github.com/Splidejs/splide/pull/169

pingvoid avatar Oct 29 '20 15:10 pingvoid

@tonyastley That seems to work fine: https://jsfiddle.net/8doz13hf/

I guess the script version is old.

NaotoshiFujita avatar Nov 22 '20 08:11 NaotoshiFujita

@NaotoshiFujita There seems to be an issue with lazy loading srcset images if using cover: true as the background url is set to the default image src value as opposed to the appropriate srcset image.

https://jsfiddle.net/habitualshaker/pegxcLso/3/

If you inspect the html for the image you will see the background image is set to https://source.unsplash.com/random/600x300?sig=6 (which is the default value).

habitualshaker avatar Feb 10 '21 13:02 habitualshaker

Lazyload does not work for different resolutions

akiragothick avatar Feb 21 '21 23:02 akiragothick

Close the issue due to the major version update. Feel free to create a new issue or open a new discussion.


The cover option is not compatible with srcset lazy loading.

NaotoshiFujita avatar Oct 09 '21 14:10 NaotoshiFujita