A user encountered warnings in their theme.liquid file suggesting they use the preload argument for image and stylesheet tag filters instead of manually writing <link rel="preload"> tags for LCP (Largest Contentful Paint) optimization.
Key Technical Guidance:
The warnings recommend using Shopify’s preload_tag Liquid filter rather than hardcoded preload links
While the resulting HTML is similar, preload_tag also adds HTTP headers, making it slightly more effective
For responsive images with srcset, using imagesrcset for preloading may be more appropriate than preloading a single image file
Would not change much in relation to LCP because the resulting HTML code is the same.
However, preload tags also add HTTP headers, so, ultimately are a bit more effective.
Also, consider that your first code – would load only one image, while mostly themes use responsive images with srcset. So consider using imagesrcset for preloading image – https://web.dev/articles/preload-responsive-images
Also, consider that your first code – would load only one image, while mostly themes use responsive images with srcset. So consider using imagesrcset for preloading image – https://web.dev/articles/preload-responsive-images
Yes I understand that, its the only image that needs it. So what would that line of code look like if i amended it:
In imagesrcset or
In preload_tag
Also, In terms of the css stylesheet, what would that code look like if i were to use the stylesheet tag filter,
Ok cool, FYI Its the only image (ie: LCP resource) I need to prioritise.
So, ultimately, what would that line of code look like if I were to mod that line in theme.liquid, with the preload_tag or with the imagesrcset. Ditto with the stylesheet_tag filter.
Or maybe the imagesrcset would be a better option – to load a smaller image, but start a bit later.
This you would need to construct yourself to mimic the srcset and sizes on your tag.
I updated my code without the master parameter, like below:
{{ ‘image.jpg’ | preload_tag: as: ‘image’ }}
Which code is better?
Just for some context, the image file im using this code is an above-the-fold image so I could use master, but in your opinion, would website performance be better off with it or without it.