Stumble Digg Technorati Delicious

Blazing Fast Ads, Don’t Let OpenX Slow You Down

Buzz This!
September 19th, 2009 by Jesse

If you serve your own advertisements using OpenX you are among the growing number of people that have taken control of their own ad serving platform. I have been using it on clients sites as well as my own sites for several years and have no plans of changing to any other system, OpenX has worked very well for me on small sites as well as high volume sites with thousands of ads.

What many people don’t know however is that by default OpenX wastes resources and slows down the loading of your pages and in some instances can cause your page load times to be so terrible that people will just move on to another site. I should clarify this a bit, it’s not the fault of OpenX as they do make available the option to rectify this, but its not a default thing and many people never look any further than the quickest and easiest way to serve your ads on your site.

If you install OpenX on your own server, you will likely be using a bit of code in each ad location that looks something like this:

<script type='text/javascript'><!--//<![CDATA[
var m3_u = (location.protocol=='https:'?'https://example.com/openx/www/delivery/ajs.php':
'http://example.com/openx/www/delivery/ajs.php');
var m3_r = Math.floor(Math.random()*99999999999);
if (!document.MAX_used) document.MAX_used = ',';
document.write ("<scr"+"ipt type='text/javascript' src='"+m3_u);
document.write ("?zoneid=11");
document.write ('&amp;cb=' + m3_r);
if (document.MAX_used != ',') document.write ("&amp;exclude=" + document.MAX_used);
document.write (document.charset ? '&amp;charset='+document.charset : (document.characterSet ? '&amp;charset='+document.characterSet : ''));
document.write ("&amp;loc=" + escape(window.location));
if (document.referrer) document.write ("&amp;referer=" + escape(document.referrer));
if (document.context) document.write ("&context=" + escape(document.context));
if (document.mmm_fo) document.write ("&amp;mmm_fo=1");
document.write ("'><\/scr"+"ipt>");
//]]>--></script><noscript><a href='http://example.com/openx/www/delivery/ck.php?n=a3832040&amp;cb=132354835318351' target='_blank'><img src='http://example.com/openx/www/delivery/avw.php?zoneid=11&amp;cb=554851354385368516846843&amp;n=a3832040' border='0' alt='' /></a></noscript>

While this will work just fine, it’s not ideal as every single ad you serve has to be called from your server one at a time, if you have 10 125×125 ad banners in your sidebar, a banner in your header and 2 or 3 other ad placements on your site using this format can have a dramatic impact on your overall site performance.

Don’t worry though, its easy to do it the right way. OpenX offers an option to include your advertisements using what they call “single page call” serving. What this basically does is put one javascript code in your header to make it available on all pages and you simply insert a small invocation code for each ad position, doing it this way all the ads for the page are called from OpenX at once, reducing server load and speeding up the loading time of your page dramatically.

So, just what is the “official” definition of single page call, well according to OpenX Single Page Call is an invocation tag which can help reduce the load on your server and deliver ads faster. The single page call ad tag uses a JavaScript invocation method to make one HTTP request no matter how many creatives are being displayed on a page, rather than each request being made sequentially and slowing down your page load times.

The invocation code for single page call is handled at the website level within your OpenX installation, simply log into your admin section and click on Inventory, then websites and select the site you want to implement this on. Once you click on the site you want (if you have more than one there) you will see a row of tabs across the top, simply click where it says “invocation code” and select the options as you would normally and click generate.

Once generated you will be looking at a page containing all the codes for the zones you have set up for that site, it breaks them down by number and even shows you a box simulating the size and shape of the ad in that zone.

In order to implement this method of ad delivery you must insert a piece of code to your header that looks like this:

<script type='text/javascript' src='http://example.com/ads/www/delivery/spcjs.php?id=1&amp;blockcampaign=1'></script>

Then you insert the individual code for each zone in their respective locations, these codes will look something like this:

<script type='text/javascript'><!--// <![CDATA[
OA_show(1);
// ]]> --></script>

As you can see, this isn’t a terribly difficult process and the benefits can be dramatic. If you are using OpenX I strongly encourage you to use this method if you aren’t already. Any questions or comments, you know what to do.


  • I was able to speed things up even more by making the javascript file local -- just copying the linked js file into a file on my server and calling that one. It makes a noticeable difference from calling the remote file. I would still like to load it after the rest of the page like some of you, too. There is still a slight delay with when some information shows up on the page because of OpenX, but it's only by about a second.
  • I've been pretty happy using the self hosted version but for those who are
    using the Openx hosted version this may be helpful. It is still on my list
    of things to improve once I have some time to set aside for it but overall I
    am very happy with the results I have gotten from it.
  • jal
    What about the number of http requests from the client side?

    Yes SPC reduces http requests to the ad server. But when someone visits
    the site they have 21 http requests to the server in order to download 20 banners to their browser…

    Francine, it sounds like you might have a solution for this? But I couldn’t quite follow what you did.

    I guess I’m trying to find a way to suture all the javascript invocations so there’s 1 javascript file-- thereby resulting in 1 http request from the client side for all the ads.

    An external javascript file would also be cacheable further reducing load times.

    Anyone have any ideas?
  • This technique is also useful for anyone running WP-Super-Cache or WP-Cache on their blog.

    I am still not happy with the three includes (one inline and two dynamic) in the page's header since the page appears slow. The ideal solution would load all the JS at the bottom of the page and the ads could be injected after the content has loaded.
  • Yes, this is effective with various caching plugins or systems. I have been
    working on a solution to accomplish a few things with openx but haven't had
    time to complete them yet, once I do I will post about it on here.

    I have found that using this method is the best "interim" solution for now,
    with the use of server based caching of php and mysql along with combining
    and minifying my scripts and css and putting my static content on a cdn I've
    knocked my homepage load time down to the low 3 second area which works for
    me for the time being.
  • 3 seconds is a decent load time.

    I'll try to spend some time on a delayed loading solution for the ads using OpenX. I really like the server and need to *fix* this in order to put it in production at work.
  • I'd definitely be a fan of that implementation, keep me posted on how the
    "fix" works out for you :-)
blog comments powered by Disqus

"Awesome invention that will change the lives of people with disabilities, please spread the word http://rewalk.com (this is not an ad)"

7763