-
-
Notifications
You must be signed in to change notification settings - Fork 315
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[LazyImage] Webperfs and LCP considerations #1967
Conversation
83fdff3
to
437855d
Compare
e9f15a8
to
b4a659c
Compare
Good idea! |
The attribute But if you want to use <img
src="{{ preload(asset('image/large.png'), {
as: 'image',
fetchpriority: 'high',
imagesrcset: asset('image/large.png') ~ ' 1x, ' ~ asset('image/large2x.png') ~ ' 2x',
imagesizes: '100vw'
}) }}"
srcset="{{ asset('image/large.png') }} 1x, {{ asset('image/large2x.png') }} 2x"
sizes="100vw"
style="background-image: url('{{ data_uri_thumbnail('public/image/large.png', 20, 15) }}')"
fetchpriority="high"
{# Using BlurHash, the size is required #}
width="200"
height="150"
/>
In the context of LazyImage and Blurhash image generation, nope, you can generate the Blurhash image with very very low dimensions:
But more generally, yes, you don't want to load a 1200px wide image on a smartphone (~400/500px). You will prefer to load an image adapted to the device in order to reduce bandwidth consumption and increase download/display speed (especially true on mobiles with slow connections). You can achieve that by using |
The follow message only concerns today and the future (a lot have changed since this package release). I personally think this package/method in general should not be recommanded today. First thing: the browsers are doing a much better job that any JS script will allow, so i'd recommand to use their optimisations.
If you have to wait more than 100ms for an image to load, you probably have other problems (an image over-sized, not in the best format, not compressed ...). First use srcset / picture sources attributes and you'll have done 99% of the job. And if you absolutely (why?) need to display something in this tiny moment before the image is loaded, you can set some background svg, a gradient, a color.. To be complete, even the blurhash feels generally to me overkill (bringing itself some avoidable JS execution) I'm very open to debate all this and ear your opinions :) |
So for you, the following code is not recommended? <img
src="{{ asset('image/small.png') }}"
srcset="{{ asset('image/small.png') }} 1x, {{ asset('image/small2x.png') }} 2x"
{{ stimulus_controller('symfony/ux-lazy-image/lazy-image', {
src: asset('image/large.png'),
srcset: {
'1x': asset('image/large.png'),
'2x': asset('image/large2x.png')
}
}) }}
/> |
I personnaly won't recommand it, today. Main reason: why use a stimulus controller instead of loading lazy ? Using native HTML provides better results in term of performance, accessibility, SEO... |
I agree with @smnandre. I think that the LazyImage UX package should be deprecated in favor of using the native HTML/browser features to lazy-load images. |
Hi everyone, I think everyone here is right here, but also I think we don't speak about the same thing 😅 I didn't speak about image lazy-loading, which yes, should be done natively by the browser, without any JavaScript layer. I'm speaking about the LCP image which should not be lazy-loaded, it should be loaded and displayed as soon as possible. |
b4a659c
to
a46b1d3
Compare
Thanks Hugo! This contribution was finally merged. While merging I did some very minor tweaks to the text, without changing any meaning: d649652 |
Added some documentation to the LazyImage component, about LCP and webperfs considerations.
tl;dr: using the LazyImage in its initial way on the LCP image, will decrease your LCP, lower the user experience, and lower the ranking of your website on Google.
Using the
style="background-image: url(...)"
trick solves this issue, since it allows the browser to download and render the HD image the fastest as possible, while showing the blurhash during the loading.This is something I've implemented ~1 month ago on our website wamiz.com, and did some comparaison:
style="background-image: url(...)"
trick, we can see the blured image and the LCP image discovered faster: