How to hit a server in the background?

B

Bryan Field-Elliot

We're designing a web app in which some operations will take a long time
to complete (maybe two minutes). Because it's a high-volume application,
we don't want browser connections hanging open for these two-minute
intervals; that would cause a huge resource drain on the server (open
threads, etc.).

We've implemented a page which has a <meta refresh> tag in it of 15
seconds, so that the browser can "check back" with the server every so
often to see if it's done with this operation.

However, we don't like the constant page reloading.. We'd rather script
this as a javascript "background process" if this is possible...

My question is, is there a way to script some kind of page reload in
Javascript, which is done without any visible window on the screen? I'd
script it to reload every 15 seconds or so, until (for example) the text
"OK" appears in the <body> tag (or some other indicator), which would
then signal the main page to reload.

Sorry if this is a tortuously confusing question. Appreciate it if you
got this far and can offer any suggestions.
 
C

Csaba2000

I'd like to see more pages doing this kind of thing.

One thing you can do is to have an IFrame and set its source to be something like
mydomain.com/perhaps/a/directory/statusChecker.php?some=arguments&go=here

On the server side, you will then realize that this is a directive to check some status.
If it's ready, return appropriate data, otherwise send back a not ready message.
This sending back data/message is actually a page which has an onLoad
which knows about its container document (the original page)
and can access the necessary functions.

You'll have timing issues (but then again, that's your whole
reason for doing this). In particular, You'll have to have some
timeout and set semaphores in case the server or connection
goes belly up, or the response time is longer than expected
and then returning.

Good luck,
Csaba Gabor from New York

PS. You can do one way communication by setting the src on
IMAGE elements, but you have said that you actually want
returned information.
You would think that you could just load a new SCRIPT element
instead of needing to suck up pages, but I have not gotten this
to work, especially cross platform. I'd be happy to read about
other peoples' approaches.
 
B

Bryan Field-Elliot

This is clever, thank you. The returned "Status" document can contain
the javascript needed to cause the parent to reload (after the server is
done processing). Nice!

So I guess the last follow-on question is, if an IFRAME has a width and
a height of "0", does it cause any funny stuff to happen in any of the
popular browsers, or is it fine?
 
C

Csaba2000

Bryan Field-Elliot said:
This is clever, thank you. The returned "Status" document can contain
the javascript needed to cause the parent to reload (after the server is
done processing). Nice!
Or, the returned "Status" document can contain the javascript needed to
REPAINT or reconfigure the page, IF there is not much change, which
will reduce the amount of flicker the user sees
So I guess the last follow-on question is, if an IFRAME has a width and
a height of "0", does it cause any funny stuff to happen in any of the
popular browsers, or is it fine?

I seem to recollect that there are some issues with the visibility of the
IFrame, but I don't remember details. One option is to set
..style.display="none" on it. If I remember right, trying to set
focus to one of its elements when the element is not visible hangs
the page on one browser (probably NN), but I'm not sure on that.
The upshot is, you'll have to be on the lookout for issues.
Also, didn't I see that Opera allows you to permit inline frames
or not - but frankly, even if true, I think market share on this
is so small you needn't worry.

Csaba

PS. I almost forgot another idea (but I like the IFrame one better).
I think (I'm not sure - my testing was a while ago), that you could
set cookies when sending information by means of altering
the src on an IMAGE element. This would allow passive
(where the returned data can't notify the requester - which is
why I'd use the IFrame) communication of limited size. It doesn't
strike me as being structurally more simple, however, than
the IFRAME scheme.
 
S

Stephen

Bryan said:
We're designing a web app in which some operations will take a long time
to complete (maybe two minutes). Because it's a high-volume application,
we don't want browser connections hanging open for these two-minute
intervals; that would cause a huge resource drain on the server (open
threads, etc.).

We've implemented a page which has a <meta refresh> tag in it of 15
seconds, so that the browser can "check back" with the server every so
often to see if it's done with this operation.

However, we don't like the constant page reloading.. We'd rather script
this as a javascript "background process" if this is possible...

My question is, is there a way to script some kind of page reload in
Javascript, which is done without any visible window on the screen? I'd
script it to reload every 15 seconds or so, until (for example) the text
"OK" appears in the <body> tag (or some other indicator), which would
then signal the main page to reload.

[...]

Could the HTTPRequest object be useful for this?

http://jibbering.com/2002/4/httprequest.html

Regards,
Stephen
 

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
474,090
Messages
2,570,603
Members
47,223
Latest member
smithjens316

Latest Threads

Top