题
如果在互联网连接速度较慢的情况下,如何告诉Google联合供稿不要等待永远加载广告?我们可以确定一个时间,说好吗去搜索5毫秒来获取广告,否则不要延迟页面其余部分的负载。
解决方案
Firebug的 YSlow 扩展程序非常适用于此类内容,它会对您的页面加载进行基准测试并告诉你什么是缓慢的,并建议你可以用什么技术来改善事情。
例如,它会为您提供有关将JavaScript放在何处以帮助用户感知网站速度的建议。
其他提示
假设您的意思是在您的网站上,请确保您的javascript已在页面末尾加载,以便您的其他内容可以先加载
请参阅此博客项目“ Google Ads Async(异步) "可能会为你提供一个很好的起点:
<script type="text/javascript"><!--
// dynamically Load Ads out-of-band
setTimeout((function ()
{
// placeholder for ads
var eleAds = document.createElement("ads");
// dynamic script element
var eleScript = document.createElement("script");
// remember the implementation of document.write function
w = document.write;
// override and replace with our version
document.write = (function(params)
{
// replace our placeholder with real ads
eleAds.innerHTML = params;
// put the old implementation back in place
document.write=w;
});
// setup the ads script element
eleScript.setAttribute("type", "text/javascript");
eleScript.setAttribute("src", "http://pagead2.googlesyndication.com/pagead/show_ads.js");
// add the two elements, causing the ads script to run
document.body.appendChild(eleAds);
document.body.appendChild(eleScript);
}), 1);
//-->
</script>
不隶属于 StackOverflow