Objective
On my website I got 2 requirements for my image which fills the whole screen and thus should be optimized in loading time:
- It's responsive, i.e. bigger screens get better resolutions
- The LCP of it is optimal low
This seems like a frequent requirement to me, but I still could not find optimal answers for that.
My proposed solution
- Solving this seems not too hard, usage of the
srcsetattribute andsizesattribute should solve it - For this I've not found a clean solution, yet and I see multiple problems with that:
- Using an interlaced image reduces the time where the site is completely empty. But this image is still loaded over network
- Network loading can be optimized with
loading="eager"(is default anyway) andfetchPriority="high". But the latter is not supported by Firefox - A very low resolution version of the image could be inlined to HTML and later on exchanged with the full res picture as soon as this is loaded. This seems kinda hacky to me and so far a bit buggy (on Firefox the inlined image seems to disappear before the full res image is displayed which results in the image being visible, not visible for a short time and then visible again)
So my question is: Are there any solutions for this that are less hacky then the inlining and replacing solution but are also supported by all big browsers?
In general it sounds like you are on the right track: make the image as smaller as possible, discovered as early as possible, and prioritised will give it the best chance of being displayed quickly.
If the image is completely full screen it may not be considered as the LCP element (https://web.dev/articles/lcp - "Elements that cover the full viewport, that are likely to be background elements.")
Firefox is actively working on Fetch Priority (it's already available behind a flag but has not been enabled by default yet).
You can used the
decodeproperty or function to manage this better. Lots more details here (full discloser I wrote this piece): https://www.tunetheweb.com/blog/what-does-the-image-decoding-attribute-actually-do/