I want to make ads to load last.so,after all the website's page elements are loaded,wha开发者_开发知识库t code do i need to make an ad load last ?
thank you
You can put the advertisement code inside window.onload
event so that it executes after the page is loaded. Another method is to put the advertisements code at the bottom of the page because browsers read the document from top to bottom. If the advertisements are loaded via javascript you could use script injection like:
<script type="text/javascript" defer>
function loadAds(src) {
//write script
document.write('<script src="' + src + '" type="text/javascript"></script>');
}
//function call
loadAds('http://example.com/advertisements.js');
</script>
"The defer attribute gives a hint to the browser that the script does not create any content so the browser can optionally defer interpreting the script"- http://www.websiteoptimization.com/speed/tweak/defer/ ; Another article if you use Google Adsense would be: http://adsense.blogspot.com/2011/03/making-web-faster-for-all-adsense-for.html
精彩评论