Is there a way of using the <picture>
element to stop a page downloading an image when using mobile phone?
I have a site which displays a header image. Due to the site functionality, it is not possible to use CSS (background image + media query) to prevent the header image being loaded on mobile. As such I need to use a solution which makes use of either <img>
or <picture>
elements.
I was thinking that perhaps I could use the <picture>
element to load a small, clear image (e.g. 1 pixel image) on mobile and then full background image on larger screens.
<picture>
<source srcset="./images/clear-1pixel.png">
<source srcset="./images/banner.jpg" media="(min-width: 1000px)">
<img src="./images/banner.jpg" alt="Header background">
</picture>
Would this be the best approach? I tried testing it, but it seems that the mobile browser is still loading both images.