We developed a CMS using craft cms. We are having several company youtube videos to play in our site.
Now we are implemented like
<iframe loading="lazy" id="clickVideo" height="635" width="100%" src="https://www.youtube.com/embed/<code>?rel=0"> </iframe>
When we checked the page speed using google and several other sites. They are showing errors as in the screenshot below:-
The urls they are showing errors is
https://www.youtube-nocookie.com/s/player/7acefd5d/player_ias.vflset/en_US/base.js
https://www.youtube.com/s/player/7acefd5d/player_ias.vflset/en_US/base.js
How we need to fix this issue? Any other way for implementing this? Please help.
First of all, the warnings indicate that you have iframes from both youtube-nocookie.com
and youtube.com
on one page. Those are essentially the same (the former being slightly better at preserving privacy), but since they are a different origin, the browser can't reuse any assets between them. You can see this in your screenshot – the browser is loading base.js
from both origins, which means the performance impact is doubled. So the first step would be to decide whether you want to use youtube-nocookie.com
or youtube.com
and then use that domain for ALL iframes on your page. This will cut the performance impact in half.
Beyond that, embedded YouTube videos will load whatever resources Google wants them to, so you can't really optimize the player itself. You're already lazy-loading the iframes. Beyond that: