react-lite-youtube-embed icon indicating copy to clipboard operation
react-lite-youtube-embed copied to clipboard

Lazy load thumbnail image

Open Fox32 opened this issue 2 years ago • 4 comments

Is your feature request related to a problem? Please describe.

Running a lighthouse audit on my side, I get the following suggestion:

Defer offscreen images

Consider lazy-loading offscreen and hidden images after all critical resources have finished loading to lower time to interactive. Learn more.

Describe the solution you'd like

I would like to lazy load the thumbnail image to save bandwidth and load time, especially if the video is embedded at the bottom of my page. Maybe the feature is configurable on the enabled.

Describe alternatives you've considered None

Additional context Right now a background image is used for the thumbnail. It's not possible to use the native lazy loading for background images. Maybe we have to switch too using an <img> tag instead. We could still stack the image, iframe and button over each other. The only problem I see is centering the image and keeping it's aspect ration, but that should be possible too.

Fox32 avatar Feb 09 '22 16:02 Fox32

🎉 Addressed at #47, already in latest version!

ibrahimcesar avatar Feb 23 '22 12:02 ibrahimcesar

Are you sure? I don't want to replace the image, I just want to instruct the browser to lazily load it.

Fox32 avatar Feb 23 '22 17:02 Fox32

Ok @Fox32 , back to issues, this is a simple one, maybe I'll add as a sensive default also! Thanks!

ibrahimcesar avatar Feb 24 '22 09:02 ibrahimcesar

This is was one of these things you think you be easy but... We don't use the <img> element for our post image. We use the element <link> with the attribute as="image".

https://github.com/ibrahimcesar/react-lite-youtube-embed/blob/f7092b16ed500349147d0c64d5855a7426ac0700/src/lib/index.tsx#L86

I don't think the lazy option is available outside the <img> element in a native form.

I think this lib you at the time not able to provide this exactly option because of implementation (an is already using preconnect), the strategy to this would require a extra step to lazy load the component itself with a wrapper. Just to let you know I will not ship it as fast I think I would!

Thanks,

ibrahimcesar avatar Feb 27 '22 23:02 ibrahimcesar