Load ads last

M

matt

Hello Everyone,
We are serving up some regular ads that are calling for their content
before the rest of our site.
It's causing some load problems, so I'm investigating trying to defer
the loading of ads until after the page has loaded.

My first solution was to put the ad strings into an array of ads and
have them looped through and attached to the body onload.

Here is an example ad:
var ads = [];
ads.push('<scr' + 'ipt' + ' language="javascript"><!-- var dc=document;
var date_ob=new Date();dc.cookie=\'h2=o; path=/;\';var
bust=date_ob.getSeconds();if(dc.cookie.indexOf(\'e=llo\') <= 0 &&
dc.cookie.indexOf(\'2=o\') > 0){dc.write(\'<scr\'+\'ipt
language="javascript"
src="http://mediapeople\');dc.write(\'/w/pop.cgi?sid=16453&m=2&tp=2&v=1.8&c=\'+bust+\'"></scr\'+\'ipt>\');date_ob.setTime(date_ob.getTime()+43200000);dc.cookie=\'he=llo;
path=/; expires=\'+ date_ob.toGMTString();} // -->' + '</scr' + 'ipt>')
;

function placeAds() {
for(var i =0; i < ads.length; i++) {
var fragment = document.createDocumentFragment();
var div = document.createElement('div');
div.innerHTML = ads;
fragment.appendChild(div);
document.body.appendChild(fragment);
}
}
window.onload=placeAds;

There are two problems:
1. The <!-- comment actually stops the javascript from running with
this tactic.
2. When the javascript does run it rewrites the page. Doh!

Does anyone have a more elegant solution for this?
Thanks
-matt
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top