Is there ANY method to delay the loading of 3rd party javascript advertisements until the rest of the page has finished loading? When my ad server gets sluggish, it delays the output of my site, which is killer.

And yes, I already know about using position:absolute to place the JS code at the bottom of the page and absolutely position the ad where I want it. Unfortunately that's really hard to do with my layout, however.

Try adding the "defer" attribute to the end of your script tags.
i.e.(<script type='"text/javascript" defer>your javascript</script>

With this attribute, the code inside the script tags will only get executed when the page has been loaded completely.

Thanks. Unfortunately, this only works for script files inside <head>. I've actually just succumbed to the pressure and did a whole bunch of fancy absolute positioning tricks. So we'll see how it goes :)

Thanks. Unfortunately, this only works for script files inside <head>. I've actually just succumbed to the pressure and did a whole bunch of fancy absolute positioning tricks. So we'll see how it goes :)

Here is a quick test with the scipt in the body. If you remove defer from the script tag and run the html, you will get a script error.

<html>
<head>
<style>#TestDefer{display:none;}</style>
</head>


<body>
<script language="javascript" type="text/javascript" defer>
alert(document.getElementById('TestDefer').innerHTML);
</script>

<div id=TestDefer >
This Text should display in the alert if defer is present in the script.
</div>
</body>
</html>

:)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.