A post on DEV Community looks at what Shopify's image_tag filter already does and what it leaves to theme developers. The author says they used to write their own lazy-loading code in every theme, then deleted most of it after reading the documentation closely.
According to the post, image_tag adds width and height attributes taken from the image, which prevents layout shift. It builds a srcset, a list of image files at different widths that lets the browser pick one. It adds loading="lazy" to images in sections lower on the page. Through image_url it also serves a modern format such as WebP or AVIF where the browser supports it, so no picture element is needed.
The author flags one catch. The srcset only goes up to the width you request in image_url. Ask for 600px and a retina screen never gets more, so the image looks soft. The advice is to request the largest size the image could display at, up to a cap of 5760px, and let srcset serve smaller ones.
Two gaps remain. First, image_tag does not know the image's layout width, so without a sizes attribute the browser assumes full viewport width and downloads oversized files in product grids. Second, the hero image, usually the Largest Contentful Paint (LCP) element, needs loading="eager", fetchpriority="high" and ideally a preload hint. image_tag has a preload parameter that sends a Link header, and Shopify's docs say to use it sparingly. Other HTML attributes pass straight through.
To spot the first section, the author uses section.index, the 1-based position within its location. It returns nil in the theme editor, in static sections and in Section Rendering API responses, so the hero may show as lazy there. The author checks results with a mobile Lighthouse run and the Network panel on the live storefront.
Why it matters
LCP measures how quickly the main visible content appears, and it feeds into Core Web Vitals, Google's page experience metrics. The post argues that the two things image_tag does not do, sizes and hero prioritisation, are the ones that most affect it.
Many custom Shopify sections may be missing one or both, according to the author. Fixing them is mostly small template edits, and checking on the real storefront rather than the theme editor avoids false alarms.
Source: DEV Community. This brief summarises their reporting; read the original for the full detail.