Shopify's image_tag already lazy-loads. Here's what it leaves to you.
I used to write my own lazy-loading logic in every Shopify theme. Then I read the image_tag docs properly and deleted most of it. Shopify already does more than people think, and the two things it doesn't do are the ones that actually move LCP. Here's what you get for free, what you still have to write, and a hero snippet I now paste into most theme builds. What image_tag does on its own {{…
Shopify's image_tag automatically implements lazy-loading, but it doesn't provide everything needed for optimal performance. Image_tag automatically adds width and height attributes, a srcset for various widths, lazy-loading to non-critical images, and uses modern formats like WebP or AVIF. However, it lacks information about the image's size in the layout and doesn't handle the hero section efficiently.
To optimize your Shopify theme, you need to specify the image size using the 'sizes' parameter, and for the first image (often the LCP element), set 'loading' to 'eager', 'fetchpriority' to 'high', and use the 'preload' parameter with a Link preload hint. This allows Shopify to control which section is considered the hero, even if the merchant rearranges sections.
A liquid snippet can be used to dynamically assign 'eager' loading and 'high' fetchpriority to the first section, while lazy-loading is applied to others. This ensures your hero image loads quickly, improving your site's loading performance.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.