public
Description: Solution (that works) to prevent Google ads from stalling your page render
Homepage: http://blog.choonkeat.com/
Clone URL: git://github.com/choonkeat/postload_google_ads.git
choonkeat (author)
Thu Mar 19 00:30:04 -0700 2009
commit  2ea72a4cc085c18509e8449ad506e3b7367d2b20
tree    a9ccf07018dca646fd1e878dfa2627b87f161f10
parent  0fcc60612509b2ef311a0e0dda8a14741fa005ba
name age message
file MIT-LICENSE Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
file README.rdoc Thu Mar 19 00:30:04 -0700 2009 Fix typo in instructions [choonkeat]
file Rakefile Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
file init.rb Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
file install.rb Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
directory lib/ Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
directory tasks/ Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
directory test/ Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
file uninstall.rb Wed Mar 18 18:13:39 -0700 2009 first cut [choonkeat]
README.rdoc

Description

Problems

  1. The ads you include on your website is doing "document.write"
  2. They block your webpage from being rendered nicely — chunks appear as ads comes in

Solutions

  1. Drop ads, or change ads provider.
  2. Hack "document.write"
  3. Refactor your web page, so that ads are at the bottom & all your content renders before them
  4. Use postload_google_ads plugin to do (3) for you.

Requirements

In this implementation, jQuery, Hpricot & Rails are required.

Getting started

Make sure you give your <script> tags for google something identifiable, e.g. <script class="googleads"> Then configure the necessary controller:

  class ApplicationController < ActionController::Base
    include PostloadGoogleAds                     # step 1
    @@google_ads_cssselector = 'script.googleads' # step 2
    cattr_accessor :google_ads_cssselector        # step 3
    after_filter :postload_google_ads             # step 4
  end

Restart your Rails server and see

Tips

To prevent ads from shifting your layout, it is best to wrap your google ads <script> tag in something (e.g. div) and give it an explicit height width.

Copyright © 2009 Chew Choon Keat, released under the MIT license