i have a website and i am using webp and jpg as a fallback. in the header, i have a bis image and smaller image for mobile users.
So i have 4 files:
header-big.webp
header-small.webp
header-big.jpg
header-small.jpg
Because it is in the header, i want wo preload the image, but only the image i need. for the small and big ones i can preload it with the media-attribute.
<link rel="preload" href="header-small.jpg" as="image" type="image/jpg" media="(max-width: 575px)">
<link rel="preload" href="header-small.webp" as="image" type="image/webp" media="(max-width: 575px)">
<link rel="preload" href="header-big.jpg" as="image" type="image/jpg" media="(min-width: 576px)">
<link rel="preload" href="header-big.webp" as="image" type="image/webp" media="(min-width: 576px)">
In this case, the browser always preloads two files, depending on its width, but still just one of them will be used.
and jeah, it makes sense, because the jpg and webp can be both implemented. so of course the browser preload both.
but can i say "if you support webp, than preload the webp and do not preload the jpg"?
Thanks, Florian