Avoiding bad <SCRIPT SRC=> hanging the page

P

Pascal Damian

My HTML pages have a <SCRIPT SRC=http://remote/script> at the top'ish
of each page. Sometimes the remote host (probably due to heavy load or
flaky network connectivity) doesn't respond for a long time. This
causes the whole page to appear hanging without anything loading.

Is there some trick I can use with settimeout() so that if the remote
script cannot be loaded after, say, 30 seconds, then I can tell the
page/browser to cancel loading that script?
 
M

Martin Honnen

Pascal said:
My HTML pages have a <SCRIPT SRC=http://remote/script> at the top'ish
of each page. Sometimes the remote host (probably due to heavy load or
flaky network connectivity) doesn't respond for a long time. This
causes the whole page to appear hanging without anything loading.

Is there some trick I can use with settimeout() so that if the remote
script cannot be loaded after, say, 30 seconds, then I can tell the
page/browser to cancel loading that script?

For IE if the script doesn't generate page content (e.g. doesn't use
document.write) try
<script defer type="text/javascript"
src="http://example.com/file.js"></script>
 
P

Pascal Damian

Martin Honnen said:
For IE if the script doesn't generate page content (e.g. doesn't use
document.write) try
<script defer type="text/javascript"
src="http://example.com/file.js"></script>

Sadly, the script does document.write(...) (as I guess most other
interesting scripts do).

Is there a way I can do something like this:

<script>
if (can't ping/connect to port 80 of remote-host in 15 seconds) {
// skip
} else {
document.write('<script src=http://remote-host/script></script>');
}
}
</script>
 
M

Martin Honnen

Lasse said:
Not just IE. The "defer" attribute is specified in HTML 4.

But Mozilla ignores it for instance so that is why I labelled that
solution as working with IE where I know it to work.
What are your experiences with Opera 7, does it take the defer attribute
into account?
 
M

Martin Honnen

Pascal Damian wrote:

Is there a way I can do something like this:

<script>
if (can't ping/connect to port 80 of remote-host in 15 seconds) {
// skip
} else {
document.write('<script src=http://remote-host/script></script>');
}
}
</script>

No, certainly not with client-side script, there might be browsers
allowing their users to specify when to to abort a connection attempt
but script doesn't allow for that.

There are some browsers that would allow you to make a HTTP HEAD request
with scripting but you can't specify a timout limit for that either

http://unstable.elemental.com/mozil...xtensions/dox/interfacensIXMLHttpRequest.html
 
H

Harag

Sadly, the script does document.write(...) (as I guess most other
interesting scripts do).

Is there a way I can do something like this:

<script>
if (can't ping/connect to port 80 of remote-host in 15 seconds) {
// skip
} else {
document.write('<script src=http://remote-host/script></script>');
}
}
</script>


Why not ask the remote host for their permission to use the script
then take a copy of it and use it from your own server?

Al.
 
M

Martin Honnen

Martin Honnen wrote:

But Mozilla ignores it for instance so that is why I labelled that
solution as working with IE where I know it to work.
What are your experiences with Opera 7, does it take the defer attribute
into account?

I just tested with Opera 7.50 and it seems to ignore the defer attribute
the same way Mozilla does.
 
K

Kien

Hi,

I think you're trying to remove the ads on your free web pages.
It's difficult.
Buy your own site and get full control of your pages.

Kien
 
P

Pascal Damian

Nope, wrong guess. :) I'm trying to _keep_ the ads on my pages (which
is hosted at a cost which I pay for, thank you very much).

The problem is, the ad network is rather flaky, sometimes they're
having network difficulty. So when that happens, my visitors are
stuck. The pages can't load.

Someone will soon say, "why don't you just switch to another ad
network?". Which of course is not a wrong suggestion, but irrelevant
to my original question.
 
M

Michael Winter

No its not.

Illegal is the wrong word, but it is forbidden in virtually every single
case[1] and liable to result in the termination of your service (if
discovered).

Mike


[1] I say "virtually" because there's bound to be a host somewhere that
neglected to add a "don't remove our banners/pop-ups" clause into the
Terms and Conditions agreement.
 
R

Randy Webb

Michael said:
No its not.


Illegal is the wrong word, but it is forbidden in virtually every
single case[1] and liable to result in the termination of your service
(if discovered).

Correct. Doesn't make it illegal, makes it a violation of the terms of
service. Pointed Head seems to be on a diatribe of late about the use of
particular words. If he wants to point fingers about the use of words,
he should take more care in his choice of words himself. YKWIM?
 

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

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,143
Latest member
SterlingLa
Top