Welcome to WebmasterWorld Guest from

Forum Moderators: open

Message Too Old, No Replies

Javascript Remote Scripting

Technique that you might find useful



6:46 pm on Apr 24, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

I recently ran across a technique of communicating between client side javascript and a server that was rather new to me. It made for an interesting feature on an application I developed that could not have been done in any other way. I thought I'd share it with you all.

The problem basically is that for javascript to interact with the server, it must load another page. This is often inefficient in terms of bandwidth, processing, etc. and also isn't as kind of a UI for the visitor(delays with pages reloading). There would be alot of great things that could be done if javascript could talk dynamically with the web server.

There are a few ways of doing this that are less than desirable such as using java(microsoft's remote scripting method). The easier way is to have javascript load a file from the server(that doesnt get displayed) and read contents from the message sent back from the server. Generally, the problem here is that this is highly browser specific, such as in the case of an iframe or ilayer, and there is still alot of bandwidth overhead.

There is an alternative that works with most any browser that allows both cookies and javascript. The basic idea is that the javascript 'preloads' an external image file on the server. Data can be passed to the server in a GET type method within the image name (ex: "image.cgi?id=427358"). The server of course only has to return 1 btye of data in the image, as the image itself is not the point. In the response headers however, the server can set a value for a cookie. Javascript can also read cookies plain as day. If it is polling(setTimeout function) for a change in the cookie value, it can detect when the response from the server has been sent and do something accordingly (popup a message box, change a text field value, etc). This all can happen VERY quickly(easily under a second on a phone modem) compared to loading a new page with updates.

Of course, there are compatibility issues with this, but for nonessential features or controlled environments, this could be very useful.

The best online resource (where I found out about this) seems to be: http://ashleyit.com/rs

Feel free to remove that link if you need to.


4:46 pm on Apr 26, 2002 (gmt 0)

10+ Year Member

Hi ggrot,

I also think this is a very interesting topic. I've experimented with Brent's libraries and they work very well.

There's a new technique discussed at dotvoid [dotvoid.com], it requires a dom browser but also is very interesting.

Here's another interesting article on Remote Scripting with IFRAME [developer.apple.com].


5:04 pm on Apr 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Interesting, I was unaware that you could load external javascript files dynamically. Thats a nice addition. The iframe stuff seems to be a slightly higher bandwidth overhead, and doesn't work on netscape 4x.


4:34 am on Apr 27, 2002 (gmt 0)

10+ Year Member

Hi ggrot,

With NN4 you can dynamically load a file into a Layer object - just like an iframe.

The iframe technique requires that the remote page call a function in the original page. Tim Scarfe [developer-x.com] and Aaron Boodman [youngpup.net] have developed a technique where this is not required (IE and Moz only). See the project at Tim's old site.

But if you need cross-browser RPC's, you just can't beat Brent's work.

I'm not quite to the point that I understand it all yet, but Scott Andrew LePera has an XML-RPC [scottandrew.com] message builder, written in JavaScript. It uses Brent's lib.


Featured Threads

Hot Threads This Week

Hot Threads This Month