How to lazy load and resize a single image from file directory?

Hi

I want to lazyload some images that are stored in the File Directory of the Shopify file admin.

This conventional system works but requires me to upload multiple sized versions of the same image.

Mist covered mountains

Question: is there a way to get Shopify to lazyload and resize a single copy of a high res image from the File Directory? E.g. Upload a large image and let Shopify resize for 180, 360, 540, 720, 900, 1080, 1296, 1512, 1728, 2048 pixels depending on screen width.

I’ve had success doing this when calling up images contained in the theme editor etc.

https://www.shopify.co.uk/partners/blog/using-responsive-images

However, I can’t seem to get it to work from the File Directory and I can’t find any documentation confirming it is possible.

Many thanks

Instead of using the file_url filter you could use the file_img_url filter which treats the file as an image, this means you could use size parameters among other filters for images.

file_img_url: https://shopify.dev/api/liquid/filters/url-filters#file_img_url

filters for images: https://shopify.dev/api/liquid/filters/url-filters#image_url

1 Like

Nice one Fili

Works a treat!

For anyone interested, see the working code below.

There may be a shorter way of writing the data-srcset section but I couldn’t find it

Mist covered mountains