2016-11-19 15 views
8

나는 수천 개의 게시물이있는 웹 사이트 (WordPress)를 가지고 있습니다. 게시물은 다음과 같습니다.Iframe 문제로 인해 페이지로드 시간이 줄어들 필요가 있습니다.

[tab:source1] 
<iframe width="560" height="315" src="https://www.youtube.com/embed/U3rKPexoEcA" frameborder="0" allowfullscreen></iframe> 
[tab:source2] 
<iframe src="https://player.vimeo.com/video/60718161?title=0&byline=0&portrait=0&badge=0" width="640" height="360" frameborder="0" webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> 
<p><a href="https://vimeo.com/60718161">HOW TO SHARPEN PENCILS</a> from <a href="https://vimeo.com/pricefilms">Pricefilms</a> on <a href="https://vimeo.com">Vimeo</a>.</p> 
[tab:source3] 
<iframe width="640" height="360" src="http://www.worldstarhiphop.com/embed/100588" frameborder="0" allowfullscreen></iframe> 

내 페이지로드 시간이 두 자리 숫자로 표시되는 경우가 있습니다. 왜 이런 일이 발생하는지 이해하지만 어떻게 수정해야할지 모르겠습니다. 나도 그것을 수정하려는 :

Iframe setTimeout() 

또는 : 나는 전체 웹 사이트를 통해 모든 iframe을에 전 세계적으로이 적용 얼마나 방법 중 하나와

<script> 
(function(d){ 
    var iframe = d.body.appendChild(d.createElement('iframe')), 
    doc = iframe.contentWindow.document; 

    // style the iframe with some CSS 
    iframe.style.cssText = "position:absolute;width:200px;height:100px;left:0px;"; 

    doc.open().write('<body onload="' + 
    'var d = document;d.getElementsByTagName(\'head\')[0].' + 
    'appendChild(d.createElement(\'script\')).src' + 
    '=\'\/path\/to\/file\'">'); 

    doc.close(); //iframe onload event happens 

    })(document); 
</script> 

: 다음과 같습니다 동적 비동기 iframe이? 개별 iframe을 개별적으로 변경할 수는 없다고 생각합니다.

답변

0

출력 전에 모든 iframe을 PHP 템플릿에서 원하는 로딩 솔루션으로 대체하는 것이 좋습니다. regexp를 사용하십시오 (예 : <iframe.*src="([^"]*)".*\/iframe>). iframe width div를 포함하는 iframe을 실제 gif 및 data-src 특성을 포함하는 실제 iframe URL로 대체하는 것이 좋은 해결책이라고 생각합니다. 그런 다음 페이지가로드 된 후 div 내에서 ifs iframe을로드하십시오.