Use image_ url and image_ tag instead of manual CDN URLs
Use Shopify's built-in image optimization capabilities instead of manually constructing image markup, to ensure consistent performance optimizations across your theme.
The server is much more efficient at building out the required image sizes than constructing them one at a time. When you manually create a URL for each width in a srcset, each width requires a separate filter call, which adds significant Liquid rendering overhead. A single image_tag filter builds all srcset widths on the server in one operation. This dramatically reduces TTFB and provides consistent optimizations for width and height attributes, focal point positioning, format negotiation, and CDN cache parameters.
Early Hints (HTTP 103) support on LCP images sends the preload instruction before the HTML finishes rendering, which lets the browser begin downloading the image earlier than any other discovery mechanism.
For your LCP image, use all available optimizations. Gate the optimizations, not the image itself, so that the hero always renders:
The condition tests section.index > 1 rather than section.index == 1 because section.index is nil in the online store editor, in static sections, and in the Section Rendering API. Comparisons against nil are falsey, so {% if section.index == 1 %} with no else renders nothing in those contexts. For the full explanation, refer to Load above-the-fold and below-the-fold sections differently with section.index.
For other images, adjust based on position:
Anchor to ExamplesExamples
Anchor to Product gridProduct grid
Anchor to CarouselCarousel
Every slide except the first gets loading: 'lazy'. The first slide is visible as soon as the carousel renders, so lazy-loading it delays the download until after the browser runs an IntersectionObserver callback. When the carousel is the first section on the page, that slide is usually the LCP element, so it also gets fetchpriority: 'high'. Refer to Never lazy-load the LCP image.
Anchor to TestingTesting
- Check the Chrome DevTools Network panel to verify that the correct image sizes download for different viewports.
- Use the Responsive Image Linter Chrome extension to validate
sizesattributes. - Compare LCP time with and without
preload: trueusing the Insights tab in the Performance panel to see the LCP breakdown. - Validate Early Hints with the
?tracing=1parameter.
Anchor to ReferencesReferences
image_tagfilterimage_urlfilter- Early learnings for Early Hints at Shopify
- Responsive images on Shopify with Liquid
- Use responsive images
- Load above-the-fold and below-the-fold sections differently with
section.index - Never lazy-load the LCP image
- Mark the LCP image with
fetchpriority="high"