我在这里结束了。我正在努力加快主页的加载时间。有两个广告让我们无法进行速度测试和可用性。广告代码是脚本标记,如下所示:
<script type="text/javascript">if(typeof(cachebuster) == "undefined"){var cachebuster =
Math.floor(Math.random()*10000000000)} if(typeof(dcopt) == "undefined"){var dcopt =
"dcopt=ist;"} else {var dcopt = ""} if(typeof(tile) == "undefined"){var tile = 1}
else
{tile++} document.write('<scr'+'ipt src="AD_URL;' + dcopt + ';tile=' + tile +
';sz=728x90;ord=' + cachebuster + '?"></scr'+'ipt>');
</script>
<noscript>
<a href="AD_URL" target="_blank" ><img src="AD_URL" border="0" alt="" /></a>
</noscript>
这是其中一个广告的原始代码。第二个非常相似。这需要永远加载。有时只要10-15秒。不酷。
我试图做这样的事情:
$('#HeaderAd').append(function(){
var ad = '<"scr" + "ipt " type="text/javascript">if(typeof(cachebuster) == "undefined"){var cachebuster = Math.floor(Math.random()*10000000000)} if(typeof(dcopt) == "undefined"){var dcopt = "dcopt=ist;"} else {var dcopt = ""} if(typeof(tile) == "undefined"){var tile = 1} else {tile++} "</scr"+"ipt>";';
var ad2 = 'document.write("<scr"+"ipt " src="http://ad.doubleclick.net/adj/ohn.auctionarms/shooting_sports_home;pos=atf_3;" + dcopt + ";tile=" + tile + ";sz=728x90;ord=" + cachebuster + "?">"</scr"+"ipt>");';
var ad3 = '<noscript><a href="http://ad.doubleclick.net/jump/ohn.auctionarms/shooting_sports_home;pos=atf_3;sz=728x90;ord=123456789?" target="_blank" ><img src="http://ad.doubleclick.net/ad/ohn.auctionarms/shooting_sports_home;pos=atf_3;sz=728x90;ord=123456789?" border="0" alt="" /></a></noscript>';
var ad_ = document.createElement('script');
var ad_2 = document.createElement('script');
ad_.type = 'text/javascript';
ad_2.src = "http://ad.doubleclick.net/adj/ohn.auctionarms/shooting_sports_home;pos=atf_3;' + dcopt + ';tile=' + tile + ';sz=728x90;ord=' + cachebuster + '?";
ad_.innerText = 'if(typeof(cachebuster) == "undefined"){var cachebuster = Math.floor(Math.random()*10000000000)} if(typeof(dcopt) == "undefined"){var dcopt = "dcopt=ist;"} else {var dcopt = ""} if(typeof(tile) == "undefined"){var tile = 1} else {tile++} ';// + 'document.write('+ad_2.src+');';
ad_.appendChild(ad_2);
console.log(ad_);
return ad_;
});
但是这给了我jquery错误并且不会加载。广告不会加载。如果我尝试用一个'document.createElement'来做所有事情,那么它仍然不喜欢它。
我这样做错了吗?有没有更好的方法来加载这些广告异步?