I'm trying to implement retina (2x) images across my website. Our pages are built from templates where we just use standard inline images:
<img src="path/to/image.png" />
I thought I could be clever and update this with srcset
:
<img src="path/to/image.png" srcset="path/to/image@2x.png 2x" />
However, we don't have 2x variants of many of these images yet.
So I tested the srcset
attribute with a non-existent image specified as the 2x resource, thinking that since it wasn't available, the browser would just display the standard image as specified in the src
. Instead, it tried to load the missing 2x resource and displayed a broken image on the page.
Is there any way to have the browser display the 1x image as a fallback if the 2x image doesn't exist? Otherwise, I can't update the templates until every single image has a 2x variant, or we'll end up with broken images all over the place.