internet

How to make YouTube videos load faster on website

Sharing is caring!

How to make YouTube videos load faster

Is your website load slower whenever you embedded YouTube video on it

So how to solve this for your website and make load faster than ever before

Just simple steps to follow

1 Get the embed code

<iframe width=”560″ height=”315″ src=”https://www.youtube.com/watch?v=_VWyQqZwHCY” frameborder=”0″ allowfullscreen></iframe>

2 Change Code Like Below

<iframe width=”560″ height=”315″ src=”” data-src=”//www.youtube.com/embed/_VWyQqZwHCY” frameborder=”0″ allowfullscreen></iframe>

3. Add Below Java script to bottom of page

<script>
function init() {
var vidDefer = document.getElementsByTagName(‘iframe’);
for (var i=0; i<vidDefer.length; i++) {
if(vidDefer[i].getAttribute(‘data-src’)) {
vidDefer[i].setAttribute(‘src’,vidDefer[i].getAttribute(‘data-src’));
} } }
window.onload = init;
</script>

before the end body tag in your website

 

Example video

Find More about this in–depth Post here – Deferring videos