Asynchronous google ads versus Synchronous

mikesoft picture mikesoft · Apr 13, 2012 · Viewed 9.7k times · Source

I'm using google DFP.

If I use synchronous ads from google, my site loads slowly as it needs to load the ad at the same time it loads the website, and if an ad takes long to respond, then the load of the page gets paused.

If I use asynchronous ads, this is not a problem since the page will load wether or not ads are loaded. In other words, it makes the site load faster. The thing is, using asynchronous ads creates a div with fixed width and height no matter if there are ads displaying or not. So usually this creates a lot of blank space on my site, since not all ads position are being used. Same goes with synchronous ads.

Google offers a third choice that doesn't create a div, it just uses javascript to display ads, and if there aren't any ads publishing in that space, then it just doesn't display any blank space, which is good, however it behaves synchronously...

What I want is some method to use asynchronous ads and not get blank spaces in case no ad is publishing.

Thanks.

Answer

alexp picture alexp · Jul 24, 2012

I think what you're looking for is

googletag.pubads().collapseEmptyDivs();

That will hide the empty divs when there are no ads to show. Call it before this line:

googletag.enableServices();

More documentation here, for reference: http://support.google.com/dfp_premium/bin/answer.py?hl=en&answer=1650154