Usage with `<picture>` tag loads images twice
tobimori opened this issue · comments
Reproduction
https://github.com/tobimori/kirby-baukasten/blob/main/site/snippets/picture.php
Describe the bug
When using unlazy with the <picture>
tag, multiple source
elements that each have data-srcset
and an img
element with the necessary data-src
attribute, the image specified in data-src
is downloaded before data-srcset
which results in a duplicated download of those images.
Some sites where I noticed this:
Additional context
No response
Logs
No response
This is the untransformed code:
<picture class="block bg-sand md:rounded-none rounded overflow-hidden" style="--ratio: 1.4652014652015;">
<source data-sizes="auto" data-srcset="http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-800x.avif 800w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-1400x.avif 1400w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2000x.avif 2000w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2600x.avif 2600w" type="image/avif">
<source data-sizes="auto" data-srcset="http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-800x.webp 800w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-1400x.webp 1400w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2000x.webp 2000w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2600x.webp 2600w" type="image/webp">
<source data-sizes="auto" data-srcset="http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-800x.png 800w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-1400x.png 1400w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2000x.png 2000w, http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-2600x.png 2600w" type="image/png">
<img alt="" class="w-full h-full object-cover" data-sizes="auto" data-src="http://127.0.0.1:3000/media/pages/about/4433226039-1708113599/anton-1700x.png" data-thumbhash="mQiKC4QPf2uoW5jasDQJiAICiIiGhmg" height="1092" loading="lazy" style="aspect-ratio:1.4652014652015;object-position:50% 50%;" width="1600">
</picture>
OK, tricky. I guess we have to ignore the loading of the <img>
altogether, if a <source>
is present. But I'm not 100 % sure.
Thanks, I've got an idea.
Seems to be fixed, thanks!