whitelord
whitelord

Reputation: 1

How to make advertising script be the latest element loaded?

I want to make ads to load last.so,after all the website's page elements are loaded,what code do i need to make an ad load last ?

thank you

Upvotes: 0

Views: 667

Answers (1)

George
George

Reputation: 2110

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

Upvotes: 2

Related Questions