I'm building an app where users list items for sale and they can include up to five photos for each item. I'm using Azure Blob storage for storing the images.
In my app, I'll be displaying these images in several different ways and sizes. I'll show them as thumbnails, as roughly 250px in width and full size, depending on the page on which they are being displayed.
I'd like to know best practice for storing these images and sending them to the client. I have a couple choices. I could store just the single image, and then retrieve and resize it, depending on how it's going to get displayed, on the server before sending it to the client. Or, I could store several copies of each image, each with the appropriate size that will be required in the client pages.
I'm leaning towards the first option where I just save the single original copy, resize it on the server and then send it to the client. I have no experience with this sort of thing so I'm not certain the best approach, or if there are others.
Best Answer
There are couple optimizations that can be done:
In order to limit client/server round-trips, I would advise to send your images grouped. Using CSS3, you can inline multiple images in a single css file. Here is a method I wrote that merge images from a directory, as a single CSS string:
Shouldn't be too much work adapting it to fetch the images from an Azure Blob. You could also save the css string back to another blob with Gzip compression, and make it available to the cdn.
Overall, there are 3 main parameters to consider to choose the best strategy: