Remote Javascript Scripting · Curiosity is bliss

Curiosity is bliss    Archive    Feed    About    Search

Julien Couvreur's programming blog and more

Remote Javascript Scripting


Remote scripting is a way to interact with the server, rather that have to refresh the complete page to fetch new data.

For example, RSLite is a simple javascript object that allows to call the server with a certain string and get a response string back. The request is done using a image and the return value is passed using a cookie which is polled.

Remote javascript include:
Useful javascript "libraries" usually come in a separate .js file, that can be included into the html using <script type="text/javascript" language="JavaScript" src="foo.js" />. This is generally used to factorize the code out of the html or a bookmarklet.

The problem with bookmarklets is that IE 6 restricts bookmark urls to 500 characters.
But if all your bookmarklet does is dynamically insert a <script src=""> tag in the page, you can avoid this limitation by having most of the code in the remote .js file.

Here are some examples of use of this technique: Jon Udell's quote bookmarklet, Simon Willison's page weight (page weight bookmarklet) and some simple text processing bookmarklets.

Remote scripting via script include:
Remote script includes can be used as another way to interact with the server to achieve remote scripting.
For example, the dChat online chat and my port of dChat to C# will add new script tags dynamically to the DOM to call server-side functions (with a certain calling convention). The server returns javascript that ensures the DOM is cleaned after the call succeeds and can pass some additional return values in the form of client-side javascript calls.

I've also seen this used in a weird way before: you can have the server output the response javascript slowly while keeping the connection open. mod_pubsub uses this trick to delivery updates to various types of clients (flash, javascript,...).

RSLite's author, Brent Ashley, also wrote the JSRS (Javascript Remote Scripting) library.

Mozilla bug 18843 (dynamically added script not executable).

An explanation of server push via multipart mime-type content.
A server push framework in Java, based on javascript and maintaining the connection open to a servlet (pushlet).

OpenThought framework (javascript and iframes).

A project using client-side JavaScript to remotely invoke methods in ASP.NET pages.


I didn't actually write the page-weight bookmarklet. However, I did recently write a bookmarklet tutorial for SitePoint which describes the external-script include technique in additional detail:

Posted by: Simon Willison (May 4, 2004 03:42 PM) ______________________________________


Can't seem to access your RSLite thing - where's it gone?!


Posted by: aufladen (October 6, 2004 04:01 PM) ______________________________________

The link had changed. Instead of it's now
I fixed the link in my post.

Don't forget Google is your friend ;-)

Posted by: Julien (October 6, 2004 07:26 PM)
comments powered by Disqus