Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Asynchronous google ads versus Synchronous

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.

like image 906
mikesoft Avatar asked Apr 13 '12 18:04

mikesoft


3 Answers

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

like image 89
alexp Avatar answered Oct 02 '22 14:10

alexp


Try this:

<div id='div-gpt-ad-YOURDFPIDGOESHERE-1' style='width:auto; height:auto; margin:0px auto; text-align:center;'>

That should stretch or shrink the div to match the creative dimensions (and even center smaller ads in a bigger adslot)

like image 31
Mister Avatar answered Oct 02 '22 16:10

Mister


Add display: none; as in inline style to the containing div.

The collapseEmptyDivs method adds an inline style of display: none; to the parent container div. To prevent the flash of extra whitespace, I first tried adding display: none; as a css style in my stylesheet, but the style wasn't removed when the ads were loaded into the target ad unit space successfully. Moving the display: none; inline seemed to remediated the problem.

like image 37
Brian Wigginton Avatar answered Oct 02 '22 14:10

Brian Wigginton