So you have a web page and it is getting some hits. One day, you decide you might as well earn some pennies off that traffic and began copy-pasting some Google Ads into it.
But you know, Google Ads suck. They use document.write. Yep, the things we were warned against. But that's not all. Their document.write actually pulls in more javascript, which in turn say "weeeeell, while we're at it!" and start to do even more document.write! (In this aspect, Microsoft ads seem more thoughtful, or it seems from Digg's homepage).
Anyways, this chokes the browser & makes them stutter. Your web page now renders to your audience in stops and starts:
A necessary evil? There are a few things that will fix to a certain extent: 1) use "script defer" or 2) hacking document.write. Not ideal in terms of fragility, and subsequent maintenance of ads embed codes.
Let's look at the problem again: 1) Google wants you to paste the script where the ad appears, 2) Wherever the script is pasted, the browser will stutter & stall the content that comes after it.
For #2, maybe the "solution" is to paste the script AFTER all content? But wait -- doesn't that mean #1 the ads get rendered there & not where I want them? Yes, but only initially.
Why not reposition these ads to where they're supposed to be after they are constructed:
Let's say that works, unfortunately it sound convoluted & a hassle, the site has too many existing ads to migrate & our guy managing the ads doesn't code, he just copies whatever Google provides & blah blah blah...
That's what the postload_google_ads Rails plugin is for :-) site-wide benefit for minimum fuss (upfront & subsequently)
To see it in action, see this demo. Click on "Before" and "After". They 2 pages are essentially the same, but only one of them applies an "after_filter":
Until ads nework catch up to use unobtrusive javascript, I guess I'll have to settle for this.
Sweeet!!
Posted by: Herry | March 20, 2009 at 10:44 AM
Very nice indeed!
Posted by: khigia | March 23, 2009 at 11:54 PM
I like that
Posted by: Peter Giovane | October 25, 2009 at 04:56 AM
Excuse me if i am wrong but... This method only demonstrates that you can shift the code to the bottom of the page instead of having to put it in the head. I have done this method too, and just removed it again, since it does not help. At least if the goal is to increase loading speed. In fact, it makes things 'worse', that is extra code, repositioning and prob some more... 'Best way' i found until now is using iframes, which i do not like. So, you make for each ad-block a separate page and that one you can render whatever way you like. But that i find annoying, since i have multiple sites and looooots of ad-slots. So, for me, i still have to find a solution what really makes your ad-slots load after onload without the use of iframes. Hopefully Google will add an asynchrone loading option, like they have done now with Google analytics...
Posted by: OJIMA | January 24, 2010 at 11:19 PM
If you use iframes, you lose the use of context & content of the current page as hints for the ads itself.
Fear not, Google had indeed launched asynchronous api not too long ago http://googlecode.blogspot.com/2009/12/google-analytics-launches-asynchronous.html
Posted by: choonkeat | January 25, 2010 at 08:45 AM