paulirish / lite-youtube-embed

A faster youtube embed.
https://paulirish.github.io/lite-youtube-embed/
Other
5.84k stars 271 forks source link

Remove preload resource hint #102

Closed kevinfarrugia closed 2 years ago

kevinfarrugia commented 2 years ago

Currently there is a preload hint for the poster image, however I would argue that we cannot assume that the poster image should always be preloaded (the user may have more critical resources or the video is outside of the initial viewport. Also, since the rel="preload" element is being added through JavaScript, I do not think it is really being preloaded and the gains are almost nil. And if a user wants to make use of preload directly in the HTML, they will end up with duplicate link elements for the poster image (probably not a big deal).

Where we are currently preloading:

if (!this.style.backgroundImage) {
  this.posterUrl = `https://i.ytimg.com/vi/${this.videoId}/hqdefault.jpg`;
  // Warm the connection for the poster image
  LiteYTEmbed.addPrefetch('preload', this.posterUrl, 'image');

  this.style.backgroundImage = `url("${this.posterUrl}")`;
}
paulirish commented 2 years ago

Currently there is a preload hint for the poster image, however I would argue that we cannot assume that the poster image should always be preloaded (the user may have more critical resources or the video is outside of the initial viewport.

Yes, this is entirely possible. The fact that this preload is added through JS likely addresses most of the problem though, since that means this image preload is definitely last in the queue behind any preloads found in the real HTML.

And since it's a as=image, it's got a "low" network priority, so the changes of slowing down something important is mostly addressed.

Also, since the rel="preload" element is being added through JavaScript, I do not think it is really being preloaded and the gains are almost nil.

hmm well yes this is probably true. :)

And if a user wants to make use of preload directly in the HTML, they will end up with duplicate link elements for the poster image (probably not a big deal).

agree on both counts. it'll just find the resource in the cache and all is bueno.


all in all, i think this particular preload has very little value, but i also don't think its causing much harm.

paulirish commented 2 years ago

all in all, i think this particular preload has very little value, but i also don't think its causing much harm.

ok 20 minutes later and digging into #103 i am convinced. :p

closed by #106