0

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.

2
Contributors
3
Replies
4
Views
10 Years
Discussion Span
Last Post by Sailor_Jerry
0

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.

0

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 :)

0

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>

:)

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.