2

I have a beautifully slick and elegant website that loads in double quick time, until of course the banner ads are enabled! Waiting to retrieve the adds up to 10 seconds on the the page load time which for me is really frustrating as I have spent ages optimising the rest of the site.

I have tried to load the adverts via ajax or similar with mixed success. The flash based banners and the ads which simply get a snippet of html from the ad server work fine. However, there are some (PaddyPower I am talking about you) which return javascript and use document.write() to append the html advert to the DOM. The advert is never displayed.

The affiliate code:

<script type="text/javascript" src="someadserver.com/impression.aspx"></script>

The script returned by someadserver.com

document.write('Normal HTML code')

It must have something to do with cross site scripting and security but I am no expert on this. Is there a way to achieve what I want?

I don't believe caching is an option as it will skew the impressions/clickthrough statistics.

Also changing any affiliate code is not an option as it is a client's website and I want a stable and workable solution that does not rely on hacking ad code.

---EDIT---

I modified my advert class to return the advert code surrounded by <noscript> tags and at the same time save the advert code in a static member. Just after my </body> tag I use this code here:

    <?php foreach(Advert::getCachedAds() as $id => $code): ?>
    <div class="advert <?php echo $id ?>" style="visibility:hidden;">
        <?php echo $code ?>
    </div>
    <?php endforeach; ?>
    <script type="text/javascript">
        $(function(){
            $('.adContainer').each(function(index, object){
                var advert = $('div.' + $(object).attr('id')).html();
                $('div.' + $(object).attr('id')).html('');
                $(object).html(advert);
            });
        });
    </script>

This works quite nicely and reminds me of the old-skool image pre-loader scripts we used to use in the days of Netscape and dial-up connections.

Adam Pointer
  • 1,492
  • 8
  • 17
  • For clarity, are the ads causing a delay in the rest of your page content loading or are you just concerned about the total page load time? – rdjs Oct 12 '11 at 12:09
  • @rdjs - As the adverts are inline, all the external links need to be resolved before the following html can be rendered. I don't mind if external content is still quietly loading in the background as long as the primary content is visible. – Adam Pointer Oct 12 '11 at 12:12
  • Looks good. Although the mention of Netscape & dial up connections sent me into a cold sweat! ;) – rdjs Oct 13 '11 at 16:52

1 Answers1

1

You could put place-holder divs where you want your adverts to be, load the adverts after all the actual content has loaded and then move the loaded ads into place.

This will not help with the overall speed of the page but will allow your actual content to be seen without having to wait for the ads to load.

rdjs
  • 594
  • 2
  • 18
  • Not sure who your ad provider is but this site seems to have documented the kind of thing I was getting at with google ads http://semplicewebsites.com/google-ads – rdjs Oct 12 '11 at 12:27
  • There is no specific ad provider, the site is a Wordpress build which uses an Ad Manager plugin. Client copies and pastes in affiliate code from selected betting websites and I have written a class to extract the affiliate code and render in the correct place. This idea could work with a little modification. I will try it out. – Adam Pointer Oct 12 '11 at 12:33