This is a question that I struggle with every time I create a new responsive website.
Thanks to srcset (and picturefill), it is now very easy to serve different size images to different devices. srcset even has built in retina control, so devices which want higher quality images can be served them. WordPress has a plugin, soon to be integrated into core, for automatically adding srcset tags to all of your images.
The question nobody seems to answer - which size images should you actually create to begin with? (I’m talking about photos here, not SVGs).
As an example, let’s say I’m serving very large images to desktop users (say, 1400px wide). I don’t want to serve that to all mobiles as well, so I need to generate some smaller sizes. Maybe I arbitrarily choose 1024px to cover tablets, 600px wide for some larger phones, and 320px wide for the smallest phones.
Wait, but now using srcset, 320px wide mobiles with 2x retina quality want a 640px wide image, so are going to be served the way-too-big 1024px instead. OK, so let me change 600px to 640px. Wait, but now there are 375px wide iPhones, and 414px wide iPhones - and any combination of 1x, 2x, and 3x retina quality! Let alone when those devices are rotated or new ones come out, or when you consider that images (eg featured images for a blog post) may appear at different sizes in different places throughout the website before responsiveness even comes into the equation.
The more sizes I create, the more my server gets unnecessarily filled up with giant numbers of images. Do I really need to generate 20 different image sizes? How do I balance creating a new size vs having an unnecessary large download for a certain device?
At this point, I usually end up thinking I should avoid srcset, and use the picture element. This way I can just generate a small number of sizes - 320, 640, 1024 (though whether those are good choices I don’t know) - and ensure that mobiles get served the smallest one that will fit, ignoring the retina side of things. That might result in slightly blurry images due to the lack of retina quality, but a much faster page load, a key factor on mobiles.
And then of course I read https://css-tricks.com/responsive-images-youre-just-changing-resolutions-use-srcset/, which says you shouldn’t do that at all.
Does anyone have any advice on this matter?