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

casino bonus casino bonus online casino bonus | [url=https://onlinecasinoss.us.org/]online casino bonus[/url]

online casino bonus slots for real money slots for real money [url=https://onlinecasinoslotsnow.com/]casino real money[/url]

gsn casino games online casino games real money casino [url=https://casinoslotsy.us.org/]free online casino slots[/url]

gsn casino games online casino games real money casino [url=https://casinoslotsy.us.org/]free online casino slots[/url]

real money casino gsn casino games slots for real money [url=https://onlinecasinoslotsparty.com/]gsn casino[/url]

real money casino gsn casino games slots for real money [url=https://onlinecasinoslotsparty.com/]gsn casino[/url]

play casino mgm online casino gsn casino | [url=https://online-casinoss.us.org/]usa online casino[/url]

buy painkillers online overnight buy tramadol buy tramadol online | [url=https://buytramadol.us.org/]tramadol 100 mg[/url]

bovada casino online casino slots online casino [url=https://casinoslotssy.us.org/]online gambling casino[/url]

online casino slots gsn casino games casino slots [url=https://onlinecasinoslotsnow.com/]usa online casino[/url]

online casino online gambling casino casino bonus [url=https://casinoslotsy.us.org/]casino play[/url]

online casino online gambling casino casino bonus [url=https://casinoslotsy.us.org/]casino play[/url]

mgm online casino mgm online casino gsn casino games [url=https://onlinecasinoster.us.org/]gsn casino[/url]

mgm online casino gsn casino online casino games [url=https://onlinecasinormoney.com/]gsn casino games[/url]

mgm online casino gsn casino online casino games [url=https://onlinecasinormoney.com/]gsn casino games[/url]

gsn casino games real money casino mgm online casino [url=https://onlinecasinolc.com/]online casino slots[/url]

gsn casino games real money casino mgm online casino [url=https://onlinecasinolc.com/]online casino slots[/url]

online casinos real money casino real money casino [url=https://onlinecasinorealmoney.us.org/]best online casinos[/url]

online casinos real money casino real money casino [url=https://onlinecasinorealmoney.us.org/]best online casinos[/url]

tramadol hydrochloride tramadol 100 mg tramadol opioid | [url=https://buytramadol.us.org/]tramadol 50 mg[/url]

tramadol hydrochloride tramadol 100 mg tramadol opioid | [url=https://buytramadol.us.org/]tramadol 50 mg[/url]

online casino gambling casino slots online gambling | [url=https://onlinecasinoss.us.org/]online casino gambling[/url]

online casino games best online casinos online casinos | [url=https://online-casinoss.us.org/]online casinos[/url]

free online casino slots real money casino gambling sites [url=https://onlinecasinoster.us.org/]casino slots[/url]

best online casinos online casino casino slots [url=https://onlinecasinormoney.com/]online casino games[/url]

casino slots gambling sites online casino slots [url=https://onlinecasinolc.com/]online casinos for us players[/url]

casino slots gambling sites online casino slots [url=https://onlinecasinolc.com/]online casinos for us players[/url]

online casinos play casino casino online [url=https://onlinecasinorealmoney.us.org/]online casinos for us players[/url]

tramadol 100 mg tramadol hcl 50mg tramadol 50 mg tablet | [url=https://buytramadol.us.org/]tramadol opioid[/url]

tramadol 100 mg tramadol hcl 50mg tramadol 50 mg tablet | [url=https://buytramadol.us.org/]tramadol opioid[/url]

bovada casino online casinos bovada casino [url=https://onlinecasinolc.com/]casino games[/url]

gsn casino slots casino online gambling sites [url=https://onlinecasinoster.us.org/]gambling sites[/url]

gsn casino slots casino online gambling sites [url=https://onlinecasinoster.us.org/]gambling sites[/url]

gsn casino best online casinos online gambling [url=https://onlinecasinormoney.com/]mgm online casino[/url]

gsn casino best online casinos online gambling [url=https://onlinecasinormoney.com/]mgm online casino[/url]

online casino usa online casino online casinos for us players [url=https://onlinecasinorealmoney.us.org/]best online casinos[/url]

online casino usa online casino online casinos for us players [url=https://onlinecasinorealmoney.us.org/]best online casinos[/url]

tramadol 100 mg tramadol 50mg tramadol hcl 50mg | [url=https://buytramadol.us.org/]ultram[/url]

mgm online casino casino slots online casino games | [url=https://onlinecasinoss.us.org/]casino slots[/url]

mgm online casino casino slots online casino games | [url=https://onlinecasinoss.us.org/]casino slots[/url]

[img]https://besplatka.ua/aws/24/44/95/74/app/prodvinem-vash-sait-v-poiskovoi...

[url=https://webcrasty.ru/][img]http://s01.geekpic.net/dm-Z5F535.gif[/img][/url]

Для сайтов на Wordpress это можно сделать с помощью плагина Related Posts, для Joomla – iRelated Articles, для Bitrix и других CMS рекомендую бесплатный сервис Relap. Огромное количество других интересных плагинов можно найти в следующих статьях: И еще очень рекомендую к прочтению вот эту статью – «Как создать сайт на WordPress: полное руководство для новичков». На сегодняшний день это самый полный материал по созданию и оптимизации сайтов на Wordpress. Как это сделать? [b][u][url=https://webcrasty.ru/prodvizhenie-sajtov-raskrutka/tjumen/]раскрутка сайта что это г Тюмень[/url]. [/b][/u] 33. Кнопки «Поделиться» для расшаривания контента. Самыми лучшими сервисами, на наш взгляд, являются следующие три: Поделиться от «Яндекс», Share42 и Po.st. Также рекомендуем использовать сервис ImageSharer от SumoMe. 34. Онлайн-консультант. Для увеличение конверсии попробуйте добавить на свой сайт онлайн-консультант (например, JivoSite). «Яндекс» [url=https://webcrasty.ru/prodvizhenie-sajtov-raskrutka/tjumen/]бесплатная раскрутка сайта в поисковых системах в Тюмени[/url]. В нашем бизнесе этот инструмент работает просто великолепно, в каких-то других – вообще не работает и только раздражает пользователей. Поэтому здесь нужно тестировать, тем более, что многие онлайн-чаты предоставляют такую возможность совершенно бесплатно. 35. Полезные статьи.

теги: [u][b]как правильно раскрутить сайт в интернете г Тюмень, [/b][/u] раскрутка сайтов что это такое г Тюмень, продвижение сайтов в Тюмени, раскрутка г Тюмень, раскрутка сайта в интернете бесплатно Тюмень, сео продвижение цена в Тюмени, как раскрутить сайт бесплатно видеоурок г Тюмень, [b][u]продвижение сайта интернет магазина в Тюмени, [/b][/u] продвижение сайта стоимость в Тюмени, самостоятельная раскрутка и продвижение сайтов в Тюмени, [u][b]раскрутка сайта туристической компании в Тюмени, [/b][/u] продвижение сайтов в Тюмени,

[img]https://image.ibb.co/jb7P0J/image.png[/img]

http://stage-forums.roadbikereview.com/doping-forum/can-i-get-33-boxes-s...
http://5tclassifieds.com/forums/topic/paper-converting-machine-company-b...
http://forums.rpgbg.net/viewtopic.php?f=18&t=10788&p=191046#p191046

online casinos online casino slots online casino games [url=https://onlinecasinolc.com/]bovada casino[/url]

online casinos for us players slots for real money mgm online casino [url=https://onlinecasinoster.us.org/]gsn casino[/url]

play casino bovada casino casino online [url=https://onlinecasinormoney.com/]casino online[/url]

online casino games usa online casino online casino [url=https://onlinecasinorealmoney.us.org/]gsn casino slots[/url]

online casino games usa online casino online casino [url=https://onlinecasinorealmoney.us.org/]gsn casino slots[/url]

ultram 50 mg tramadol generic ultram 50 mg | [url=https://buytramadol.us.org/]tramadol 100 mg[/url]

ultram 50 mg tramadol generic ultram 50 mg | [url=https://buytramadol.us.org/]tramadol 100 mg[/url]

mgm online casino online casino slots casino blackjack [url=https://onlinecasinolc.com/]online casino games[/url]

play casino casino blackjack online casino gambling [url=https://onlinecasinoster.us.org/]online gambling casino[/url]

Pages

Add new comment