You were ahead of your time in 2013 and thankfully in 2022 things are starting to catch up :P
The top answer only tells half the story (using display:none
with media queries) because even though the image is not displayed it will still be loaded (causing a performance hit).
If the image isn't at the top of the page (for desktop) then you're in luck and can just add lazy loading for the image.
If you are using the image as your background, I suggest you rather look into using CSS - specifically background-image: image-source coupled with a media query to exclude the image on mobile.
.bg {
background-image: -webkit-image-set(
url("images/Background_1.jpg") 1x,
url("images/Background_2.jpg") 2x);
background-image: image-set(
url("images/Background_1.jpg") 1x,
url("images/Background_2.jpg") 2x);
}
@media (max-width: 600px) {
.bg {
background-image:none;
}
}
Unfortunately it's hard to go all the way with the optimisations at the moment because you may also wish to use different file formats (e.g. webp or avif) - and these aren't well supported at all. There are some workarounds, which are described in this answer: https://stackoverflow.com/a/59970037/1912127
I would be very interested to find out what solution you came up with in 2013.