iframe - YouTube embeds slowing down page -
i have page bunch of thumbnail images when clicked open embedded youtube videos in modals.
here html:
<li> <div class="videold"> <a class="video-link" title="video title" href="#video" role="button" data-toggle="modal" data-id="youtubeid"> <img class="responsive-imamge" src="//www.mysite.com/video.jpg" alt="" > </a> <h4>video title</h4> <p>video description</p> <div id="video" class="modal hide fade in" tabindex="-1" role="dialog" aria-labelledby="mymodallabel" aria-hidden="true"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> <img src="www.mysite.com/close-modal.png" alt=" "> </button> <div class="modal-body"> <div class="video-wrapper"> <!-- on click iframe append here --> </div> </div> </div> </div> </li>
i'm displaying list of 5 video thumbnails way. has slowed down page load time. before adding videos page loaded 61% faster avg on site. it's 21% slower.
is there way optimize these videos load when video thumbnail clicked?
edit
thought i'd update , share i'm using now. instead of using lazyyt plugin created simple on click function appends iframe container div. link video has data-id attribute contains youtube video id.
$('.video-link').on('click', function () { var youtubeid = $(this).data('id'); var code="<iframe width='1280' height='720' src='//www.youtube.com/embed/" + youtubeid + "?rel=0&autoplay=1' frameborder='0' allowfullscreen=''></iframe>"; $(this).parent().find('.video-wrapper').append(code); });
have thought lazy loading youtube videos instead?
i haven't used myself, jquery plugin lazy load youtube videos. here another plugin lazy load, unfortunately seems both of them require jquery isn't ideal unless site using it.
there another answer on covers question , might give more insight.
Comments
Post a Comment