Speed up page load times when running Google ads

Google ads are an easy way to monetize your site, but their implementation leaves a lot to be desired. To insert a Google ad block on a page one has to insert two script blocks: one to set the adverts parameters, and one to load the external Google script.

The problem is that the scripts have to be inserted in the body at the place where the advert is desired. This is because Google uses JavaScript's document.write to generate an iframe, which then loads the ad. If Google's servers are being a bit laggy then your visitor has to wait for the Google script to finish loading before the rest of the page is rendered. The closer your ad is to the top of the page, the worse the resulting problem is.

A number of solutions have been proposed, including overwriting the document.write method, and inserting the Google script through DOM manipulation. Unfortunately this breaks in Safari 2.0, and breaks any other instances of document.write you may be using.

So here is the solution we've come up with:

Normal set-up

<body>
	Content above advert
	<script type="text/javascript"><!--
		Google ad params
	//--></script>
	<script type="text/javascript" src="...show_ads.js"></script>
	Content below advert
</body>

Optimised set-up

<body>
	Content above advert
	<div id="ad1_inline"></div>
	Content below advert
	<div id="ad1_footer" style="display: none;">
		<script type="text/javascript"><!--
			Google ad params
		//--></script>
		<script type="text/javascript" src="...show_ads.js"></script>
	</div>
	<script type="text/javascript">
		window.onload = function() {
			document.getElementById('ad1_inline').appendChild(document.getElementById('ad1_footer'));
			document.getElementById('ad1_footer').style.display = '';
		}
	</script>
</body>

What it does

  1. Creates a place-holder div for the where the ad will end up
  2. Places all the ad code in an "footer div" at the bottom of the page - this prevents your page from "locking" while the Google scripts load
  3. Hides the footer "footer div" with css so the ads don't ever show below your page, causing the page height to "jump"
  4. Waits for the whole page to load before moving the ads (the window.onload bit) thus preventing Internet Explorer from getting really upset.
  5. Moves the ad to it's placeholder, and un-hides it

Of course you may not want to use window.onload. If you attach the function to an event you can modularise the whole ad insertion in your code. Using a JavaScript library (Prototype in this case, but others will look similar) results in the following change to the last script:

	...
	<script type="text/javascript">
		Event.observe(window, 'load', function() {
			$('ad1_inline').appendChild($('ad1_footer'));
			$('ad1_footer').show();
		}
	</script>
	...

All scripts are Public Domain.

Comments

empire city online casino free online casino online gambling free casino games slotomania | https://onlinecasinoplay.us.org/ - slots for real money https://onlinecasinoplay.us.org/ - real casino

gsn casino play casino play online casino free vegas casino games | https://onlinecasinoplay.us.org/ - casino games slots free https://onlinecasinoplay.us.org/ - free online casino

gsn casino play casino play online casino free vegas casino games | https://onlinecasinoplay.us.org/ - casino games slots free https://onlinecasinoplay.us.org/ - free online casino

free online slots big fish casino casino blackjack | https://onlinecasino888.us.org/ - free casino games sun moon

free online slots big fish casino casino blackjack | https://onlinecasino888.us.org/ - free casino games sun moon

viagra overdose does generic viagra work viagra women generic viagra

real money casino three rivers casino grand falls casino no deposit casino | https://onlinecasinox.icu/ - playmgm nj casino online https://onlinecasinox.icu/ - empire city casino online

san manuel casino casino game gsn casino slots soaring eagle casino | https://freeonlinecasino.icu/ - lady luck online casino https://freeonlinecasino.icu/ - free casino games vegas world

free vegas world slots gold fish casino slots slots free caesars free slots | https://realmoneyslots.icu/ - slots games free https://realmoneyslots.icu/ - real casino slots

san manuel casino online casino games free real casino slots hollywood casino | https://onlinecasinox.icu/ - casino near me https://onlinecasinox.icu/ - winstar world casino

san manuel casino online casino games free real casino slots hollywood casino | https://onlinecasinox.icu/ - casino near me https://onlinecasinox.icu/ - winstar world casino

name brand viagra when will viagra be generic viagra for men is viagra generic

sugarhouse casino online pechanga casino river spirit casino tulsa royal river casino | https://freeonlinecasino.icu/ - hollywood casino online https://freeonlinecasino.icu/ - golden nugget online casino

sugarhouse casino online pechanga casino river spirit casino tulsa royal river casino | https://freeonlinecasino.icu/ - hollywood casino online https://freeonlinecasino.icu/ - golden nugget online casino

online slots free free slots vegas world slots of vegas free slots online no download | https://vegasslotsonline.icu/ - turning stone online slots https://vegasslotsonline.icu/ - play slots online

online slots free free slots vegas world slots of vegas free slots online no download | https://vegasslotsonline.icu/ - turning stone online slots https://vegasslotsonline.icu/ - play slots online

muckleshoot casino vegas casino games mohegan sun casino seneca niagara casino | https://slotsonline.ooo/ - foxwoods casino online slots https://slotsonline.ooo/ - hollywood online casino

caesars free slots free casino slots games goldfish casino slots free free online slots no download no registration | https://realmoneyslots.icu/ - free games online slots https://realmoneyslots.icu/ - free vegas world slots

caesars free slots free casino slots games goldfish casino slots free free online slots no download no registration | https://realmoneyslots.icu/ - free games online slots https://realmoneyslots.icu/ - free vegas world slots

huuuge casino playmgm nj casino online online casino bonus gun lake casino | https://onlinecasinox.icu/ - casino games https://onlinecasinox.icu/ - virgin casino online

spirit mountain casino play online casino morongo casino casino online | https://freeonlinecasino.icu/ - play online casino https://freeonlinecasino.icu/ - winstar world casino

free slots vegas free games online slots goldfish casino slots free heart of vegas free slots | https://vegasslotsonline.icu/ - online slot games https://vegasslotsonline.icu/ - house of fun slots

free slots vegas free games online slots goldfish casino slots free heart of vegas free slots | https://vegasslotsonline.icu/ - online slot games https://vegasslotsonline.icu/ - house of fun slots

casino games online seneca allegany casino free online casino games red rock casino | https://slotsonline.ooo/ - caesars online casino https://slotsonline.ooo/ - stn play online casino

caesars slots free casino slot games free freeslots.com slots free slots with no download or registration | https://realmoneyslots.icu/ - vegas world free slots https://realmoneyslots.icu/ - free vegas slots online casino

posh casino free vegas casino games slots casino games pechanga casino | https://onlinecasinox.icu/ - sandia casino https://onlinecasinox.icu/ - parx online casino

posh casino free vegas casino games slots casino games pechanga casino | https://onlinecasinox.icu/ - sandia casino https://onlinecasinox.icu/ - parx online casino

free slots casino games pop slots casino wheel of fortune slots free slots | https://vegasslotsonline.icu/ - free casino slots games https://vegasslotsonline.icu/ - free casino slot games

rivers casino doubleu casino on facebook casinos near me parx casino online | https://freeonlinecasino.icu/ - bovada blackjack https://freeonlinecasino.icu/ - royal river casino

foxwoods online casino spirit mountain casino virgin casino online nj winstar world casino | https://casinoo.ooo/ - turning stone casino https://casinoo.ooo/ - gsn casino games

foxwoods online casino spirit mountain casino virgin casino online nj winstar world casino | https://casinoo.ooo/ - turning stone casino https://casinoo.ooo/ - gsn casino games

playmgm nj casino online zone online casino sugarhouse online casino slots casino games | https://slotsonline.ooo/ - del lago casino https://slotsonline.ooo/ - firekeepers casino

goldfish slots caesars free slots online free games for casino slots hollywood celebrity slots | https://realmoneyslots.icu/ - penny slots free https://realmoneyslots.icu/ - free vegas world slots

goldfish slots caesars free slots online free games for casino slots hollywood celebrity slots | https://realmoneyslots.icu/ - penny slots free https://realmoneyslots.icu/ - free vegas world slots

play free slots free casino slots gold fish casino slots casino games slots free | https://vegasslotsonline.icu/ - hollywood casino free slot play https://vegasslotsonline.icu/ - free slots vegas

play free slots free casino slots gold fish casino slots casino games slots free | https://vegasslotsonline.icu/ - hollywood casino free slot play https://vegasslotsonline.icu/ - free slots vegas

dakota sioux casino blue chip casino free casino slot games slots casino games | https://onlinecasinox.icu/ - hollywood casino online https://onlinecasinox.icu/ - casino slot

dakota sioux casino blue chip casino free casino slot games slots casino games | https://onlinecasinox.icu/ - hollywood casino online https://onlinecasinox.icu/ - casino slot

vegas casino online online casinos for us players seneca niagara casino sugarhouse casino | https://casinoo.ooo/ - virgin casino online nj https://casinoo.ooo/ - sugarhouse online casino

cashman casino borgata online casino real money casino real casino | https://freeonlinecasino.icu/ - sandia casino https://freeonlinecasino.icu/ - spirit mountain casino

chinook winds casino potawatomi casino firekeepers casino mystic lake casino | https://slotsonline.ooo/ - slot machines https://slotsonline.ooo/ - slot machines

free slots free slots vegas world pop slots konami free slots | https://vegasslotsonline.icu/ - free vegas slots https://vegasslotsonline.icu/ - las vegas free slots

free slots free slots vegas world pop slots konami free slots | https://vegasslotsonline.icu/ - free vegas slots https://vegasslotsonline.icu/ - las vegas free slots

Absolutely NEW update of captchas regignizing software "XRumer 16.0 + XEvil":
captchas recognition of Google (ReCaptcha-2 and ReCaptcha-3), Facebook, BitFinex, Bing, Hotmail, SolveMedia, Yandex,
and more than 8400 another categories of captcha,
with highest precision (80..100%) and highest speed (100 img per second).
You can use XEvil 4.0 with any most popular SEO/SMM software: iMacros, XRumer, GSA SER, ZennoPoster, Srapebox, Senuke, and more than 100 of other software.

Interested? You can find a lot of impessive videos about XEvil in YouTube.

FREE DEMO AVAILABLE!

Good luck!

http://XEvil.net/

ignition casino slots for real money online casino games borgata hotel casino | https://onlinecasinox.icu/ - posh casino https://onlinecasinox.icu/ - casino blackjack

ignition casino slots for real money online casino games borgata hotel casino | https://onlinecasinox.icu/ - posh casino https://onlinecasinox.icu/ - casino blackjack

borgata hotel casino free online casino soaring eagle casino belterra casino | https://casinoo.ooo/ - online casinos for us players https://casinoo.ooo/ - seneca allegany casino

Pages

Add new comment