Preventing YouTube embeds loading multiple instances of player JS?

I have noticed on many WordPress sites I work on that when there is more than one YouTube video embedded, multiple instances of the player JS will be called.

Since it’s a full megabyte of data, I am trying to determine if there is a way to have only one instance of the JS loaded. I would have thought the second (or more) instances are redundant.

Here’s what gets loaded twice, for a WP page with two embedded videos.

https://s.ytimg.com/yts/jsbin/player-en_US-vfle0WwUC/base.js (1.0MiB)

I’ve been unable to find any information on this, which is a bit surprising as I thought this would be an issue many people would be wanting to solve.

Any suggestions?

2 Answers
2

In theory youtube embedding is done as iframes, and iframe are virtual additional independent web pages which are rendered at the same window, therefor the content of one iframe can not gave an impact on other iframes.

In practice, such JS will be cached in the browser. The first one may get loaded, but the second one (unless someone in google had a big oooops moment) will be “served” from the browser’s cache.

to directly answer the question – there is not much that can be done on wordpress side to avoid it, and most likely there is nothing that need to be done

Leave a Comment