Infrequently Noted

Alex Russell on browsers, standards, and the process of progress.

Comments for What else is burried down in the depth's of Google's amazing JavaScript?


So, how does this work in Firefox then? Another technique?
by robert at
On FF (1.5), the communication iframe only makes the statusbar say "Transfering data from example.com..." while the throbber stops when a subsequent HTTP request has finished. It's much less distracting. While not perfect, it sure beats having the top thinger spinning, and a solution for the 85%+ browser is *much* more important for the acceptance of the technique.
by alex at
Is the htmlfile object documented anywhere? I can't find it on MSDN (but then I can never find anything on MSDN).
Not sure. I think the above syntax gives you a document that implements IHTMLDocument2:

http://msdn.microsoft.com/library/default.asp?url=/workshop/browser/mshtml/reference/ifaces/document2/document2.asp

Regards

by alex at
How's the rewrite of mod_pubsub going?
It's done but not yet released as Open Source software. You might ping Joyce to see what the current price for a copy is.
by alex at
Nice, but this is still a "hack", the problem is that HTML is just not suitable for RIA's. I believe that "ajax" can be used for small parts of a website, but its totally not suitable for complete webbased applications with rich interaction. One of the worst things about Ajax is that techniques are based on hacks, and not on standards. An other problem is that HTML is just not suitable for rich internet, example: if you need an accordion element, tree structure, or tab interface, you have to build it still in HTML. While in flash its just adding 1 tag and its completely rendered on the client.
by Sjors Pals at
Sjors,

Of course it's a hack. Welcome to the web. This is how real work gets done out here in the world of universal deployment.

As for Flash and components, I invite you to check out the widgets we're building in Dojo. They make building richer interfaces easier, to the extent that declaring rich components can be as little as a couple of tags. These components aren't Flash, but that's both a benefit and a liability.

Regards

by alex at
Tables were hacks too, and look at how using them turned out. I have a feeling that we're going to be repeating history with applications based on code like this.
by Jake at
Forgive the denseness, but how is this different from programatically or manually (via a click) changing the src of the iframe to a dynamic page and writing out the javascript data using some server side technology? (e.g. the "back in the old days" method) Or if you prefer, changing the location of a 0px w/h or hiddent frame?
by Scott at
Scott,

It's unique in several ways. It builds on the programmaticaly "moving" an iframe to a different URL, but with the cooperation of the server streams events down the wire without closing the connection. Furthermore, unlike hosting the iframe directly under the spawning document, this technique avoids the background "click" noise and prevents the throbber from spinning. It's a usability enhancement to a well-known technique (at least in the small community of people that care about low-latency data to the browser).

Regards

by alex at
Cheers Alex. The team are glad to know people are noticing the technical achievements of Gmail Chat. As you know, I joined the team quite late on and was equally impressed when I found out how they were handling the persistant connection, it's a stroke of Genius.
(For the record I only played a small role in this launch)
That's pretty cute. Indeed, the call will return IHTMLDocument2. I wonder if this leaks any?
Hi, Nice job going thru the js code. But did you found how gmail talk detects when you are away ?
by lescoste at
Thanks for the insight.

It's amazing how irritating that iframe click is on the sites that use that method.

by Tim at
The problem I see is that common web hosts aren't likely to be very happy, are they? As far as I can tell, using this technique with any common web host will tie up Apache workers, reducing the number of 'ready to serve' Apache workers, introducing various performance side effects, say from the number of requests going through per minute to how well you can withstand a slashdotting.
by Hull at
I think this is pretty cool, I just find the inconsistency that exist with AJAX implementation is a bit of a pain. Until the standard's grow I just don't see the movement of AJAX going any further, all we do is hack out some code for small little apps when developing the page using AJAX instead of using a standard built in method. Anyway's this was a great read!
What about the up and coming Windows Smart Client tools? I don't know much about it but I had heard it will make the "Desktop over internet" experiance even more a reality. It sounds very promising.
by Tim at
A potential downside of this approach is the need to send the complete HTML to the client, while with XmlHttpRequest you could send a more efficient XML format and let JavaScript reformat the output. This means you have to deal with more 'live' data and bandwith usage. Of course, both approaches have their advantages and the 'right tool for the job' rule applies, but I'd like to mention this nevertheless...
Hull: this stuff won't run on today's Apache (hence the link to Tiwsted). The current worker setup is just too resource intensive for "zombie" connections.

Tim: as I've said here before, you can develop richer interactions in whatever environment you like, but please don't make any mistake that if it's not HTML, CSS and JavaScript, it's not the web.

Filip: You're not sending "the complete html", you're sending small datagrams encoded in a script tag envelope. The data on the wire is usually some sort of JSON data structure.

by alex at
This isn't really new, just got associated with the shiny buzzword AJAX now. The concept of an open pending http connection exactly what iTunes does when sharing between two computers. iTunes' DAAP is really just a HTTP service between two clients. They keep an open HTTP request and if the server needs to tell the client something now it just sends a response back over that request.
I have been doing an AJAX like technology for several years now. Instead of using an ActiveX object, I simply define a number of script tags and then use javascript to assign them to send and retreive data from the server.

function loadCustomer(McustId) { document.all.general1.src="getCust.php?"+McustId }

... The php returns executable javascript, which obviously works like regular javascript. Instead of using XML, I format it so that it renders the data in the form needed for each specific case.

The issue of PUSH is interesting to me. There are many times that I would like my local application to know about events. I use polling currently. I have thought about using Flash, which has notification capabilities. Really, all that is needed is to say "Hey, its time to check the server."

I am unclear about the server aspect of this particular approach (Tiwsted)

by George at
multipart http content type is what you are looking for. Netscape already has invented that back in the 90's. http://wp.netscape.com/assist/net_sites/pushpull.html

They were just too far ahead of their time. Web weren't mature enough to use it. Here is a link on how you can implement "Serverside-Push" web application. Combine with iframe and XMLHTTPRequest Object (AKA Ajax) you can build a realtime application. Althougth according to how most server side scripting language (PHP, Perl, Python and Ruby)are integrated into the web server (each process doesn't know about other process), they are not suitable for such task.

by Tree at
Tree,

Multipart is not what we're looking for. We need something portable, and multipart isn't it. While I would personally prefer it if Opera, Safari, and IE would agree on a multipart boundary and encoding syntax, it hasn't happened. Until then, the iframe hack is the lowest latency option.

Regards

by alex at
I just started playing around with this, but it's got me stumped: I've added an onload event to the iframe, but I don't expect that to give me anything useful. Do I simply continuously check to see if the iframe's innerHTML has changed?
This is not new technology. It has been around for at least 6 years. The guy who invented it works for Oracle, and so Oracle now owns the patent on it.

I came to Oracle when it acquired PeopleSoft, which acquired a startup I was the architect for called istante software.

We use this technology in Oracle BAM to keep our business activity monitoring dashboard up to date in real time. In fact we guarantee that the time elapsed between our backend server getting a transaction committed and the time it shows up in all of the dashboard that are affected is not more than 2-5 behinds real time.

We use 1 connecion for all of the dashboard a use has on his desktop, and we "multiplex" the ActiveData through that connection (which is one of our pending patents).

We send down XML documents that only have the change each view needs to get, and not complete HTML like someone was suggesting here...

Using Oracle BAM users can build real time dashboards and alerts on any data model they define, and doing all of that happens also in 100% thin and rich web based applications (which are also using Ajax when it makes sense).

The first version n our product with all of what I mentioned shipped in 2003.

Hi Tal,

I never claimed that the technique of streaming data down the wire was new. When I re-wrote the client for the Open Source'd version of mod_pubsub several years ago, the technique was old then. We even re-implemented the hack that allowed multiple browser windows to use the same connection (think IPC over cookies).

What I did claim is that Google's improvement on it with respect to IE is novel and that it removes a significant usability barrier. If Oracle implemented this particular browser-specific workaround, that would be good to know so credit can be given where it's due.

As for patents and timing, I suggest you contact KnowNow whose business started around this technique (I believe) prior to the date you mention. There is likely not only prior art, there is prior art for the multiplexing portion and all of the client techniques.

I recommend that you do your homework on this one before claiming that your company has been wronged, that anyone is in breach of patent, or that I have stated something inaccurate. Well-informed corrections are welcome, however.

Regards

by alex at
Peter: what I blogged is only the smallest portion of the overall technique for streaming data to the client over HTTP. An onload event won't get you where you want to go. The script tags sent down the wire themselves need to call the dispatchEvent() method (or whatever your version will call it).
by alex at
Oops, I misread the article. I concluded that the data going through is the final product: HTML. Of course, HTML is less compact then XML, so that would mean more bandwidth. Obviously, I was wrong because the format doesn't have to be HTML.

This approach actually seems to be quite a viable alternative to XmlHttpRequest in some cases, so I'm definitely going to check it out and learn more about it. Thanks for mentioning it :)

Isn't this technique an updated form of "Pushlets?"

Pushlets: Send events from servlets to DHTML client browsers http://www.javaworld.com/javaworld/jw-03-2000/jw-03-pushlet.html

Discover how pushlets, a servlet-based notification mechanism, enables server-side Java objects to call back JavaScript code within a client browser.

Andrew,

It has gone by many names over the years. Pushlets was just one. IIRC, however, it scaled like a lead brick. Newer event-driven server environments that eschew Servelets and Threads in favor of CPS (Twisted and POE) or a single "keepalive dispatcher" (Apache Event MPM) allow the technique to finally scale well. Kernel level improvements like epoll and kqueue (wrapped in libevent) have accelerated this.

As for how it looks on the wire and what the client strategy is, there are many ways to skin this cat. I'm only covering a single improvement by Google to one of the better-performing approaches.

Regards

by alex at
yawn, cgiirc works (has worked) on all modern browsers using an open connection to the web server. this isn't new.
by james at
James: you clearly didn't read this. I didn't claim that the technique of streaming data to the client was new. I claimed that Google's variant on it that solves significant usability issues *is* novel.
by alex at
A super-hidden IFrame, fair enough. Does this work around the 2 max connections limit that exists in both browsers, though?

If not, has anyone come up with a clever workaround for the 2 connections limit, other than changing the registry for IE and prefs.js for Firefox (which can have other undesirable side effects)?

Alex,

I never claimed that our company has been wronged, or that anyone is in breach of patent.

We have checked prior art (including KnowNow) before we submitted the patent applications.

I agree think that Google's use of this technology is awesome, and I think that what we do with it in Oracle BAM is not less cool :)

Tal.

check out our website (soon we will have some live demos on it): http://www.oracle.com/technology/products/integration/bam/index.html

Tal.

Hey Alex,

dont know if this is all obvious to you guys, but it took me some time to figure out: in order to access a function "outside" the htmlfile ActiveX Object you'll have to set a reference under the "parentWindow" property of the ActiveX Object. e.g.

function foo() {...} transferDoc = new ActiveXObject("htmlfile"); transferDoc.parentWindow.foo = foo;

// inside the iframe parent.foo();

gmail does it the same way, so i guess there is no better solution ;) in order to avoid the "browser keeps loading" syndrom on Mozilla gmail uses the XMLHttpRequest which supports, at least under Mozilla, the readyState "INTERACTIVE". It allows access to the responseText while its still loading. Unfortunatelly there is no way to clear the responseText, so everytime the readyState occurs you'll have to substr out the stream data that you received before in order to get the newly received data. So it might be a good idea to reestablish the stream connection at some stage so the browser may free that memory. Certainly, this also applies to the iframe technique. (again, gmail does that aswell)

greets from germany,

martin

oops, i didnt know that a tripple dash does some formating stuff. would you please correct that and delete this post here?

thanx!

greets, martin

Amazing stuff. I wonder about the possibility of doing the reverse, i.e., making the file upload process much smarter.

Imagine resume, upload in blocks, etc. Besides being useful in a P2P-like situation, would be great where clients have to upload LARGE files to the server.

I know, I'm a dreamer ;)

by Rui Pinheiro at
So... Why does Google nog use this to check if there's new mail... For as much as I know, there's still a click on the 'inbox' link required to find out if there's new mail... (or maybe it does check, but not often enough?)
by Willem Mulder at
Sorry to join the conversation so late; you wrote waaay back at the start of all this:

"On FF (1.5), the communication iframe only makes the statusbar say “Transfering data from example.com…â€? while the throbber stops when a subsequent HTTP request has finished."

I've been having a very hard time reproducing that result, and I wonder if you could clarify a bit. Is it any old HTTP request on the page (i.e. an image or something), or does something fancy need to be done to make the spinner stop for Firefox?

Thanks very much!

by Jon at
Something fancy DOES need to happen. I've managed to reproduce it, but I'm not entirely sure where the magic is...
by Jon at
Has anyone experimented with this "htmlfile" object to try multiple synchronous ajax requests? Seems like you could just use this instead of XMLHttpRequest.
by sam at
Can someone (Alex?) post a working code example so we can see this Comet stuff in action ?

Would/could it work with Microsoft IIS ?

Thanks

by Nutz at
Maybe this is a stupid question, but I'm wondering one more thing. When a user (let's call them the sender) clicks on another user's name (the receiver) to chat, the sender opens up a small iframe window to chat and all this code does its magic. But how does the receiver's window know to likewise open an iframe?

My best guess is that as soon as anyone logs into Gmail, a persistent connection is established and is constantly left open, even when no one is chatting. Do you know if this is the case?

by Gordon at
This rules! I'm in the process of releasing an IFRAME based AJAX implementation that is able to get around the browser "same origin" policy (http://en.wikipedia.org/wiki/Same_origin_policy). I thought I was pretty hot stuff... until I turned off the mute button on my computer.... click, click, click, click..... ARRRRG!

However, using this ActiveXObject("htmlfile") solved my woes! No more clicks or annoying visual queues in IE! I need to stick with the "single-request" method rather than going for a persistent connection b/c it's fundamental to the way I'm able to skirt same origin (except for Opera which is known to be overly sensitive with iframe security).

Since this appears to be a well versed community, out of curiosity does anyone else here have asynchronous communcations working outside of the same origin? Would be nice to know if my architecture is as unique as I think it is, or if I simply reinvented the wheel ;)

Thanks, -Craig

by Craig at
Hi Alex,

I am very interested in using DOJO for a new website. We require realtime push, just like the google dynamic iframe solution provides. Do you have any idea when this would be implemented in DOJO?

Thanks Scott

by Scott at
Thanks Andrew,

I remembered having seen this technique at work, but could not recall it was Pushlets :)

Alex, Would it be correct to say that the client side is exactly same as Pushlets while the server side is implemented differently...or I am missing something here ? As you said, I am also curious about what other names it has gone by !

Warm regards, Abhinav

by Abhinav at
That was an awesome article, still have to go through all the other links that are present.

But all these "hacks" against the browser shouldn't go unnoticed. These new Applications, are changing the way we browse the web.

Soon I hope browsers should come up with the "Back" button for the "Last Ajax based event". I don't know how are devs @ Mozilla working towards it, probably Firefox 3.

Hi you all,

i tried the code on ie5.5 on win98 and end up with: function rpc_iframe()

{

var currentDomain = “localhost/â€?;

var dataStreamUrl = currentDomain+�rpc-test/server.php�;

var transferDoc = new ActiveXObject(�htmlfile�); // neue Seite

transferDoc.open();

transferDoc.write(�");

transferDoc.write(â€?document.domain=’â€?+currentDomain+â€?‘;â€?);

transferDoc.write(�");

transferDoc.close();

var ifrDiv = transferDoc.createElement(�div�);

transferDoc.appendChild(ifrDiv);

ifrDiv.innerHTML = “â€?;

}

Everything went fine… except the window wont close.

Any ideas to manage it? Thanks in advance

M.

by michael at
So. How do we retrieve the content from the iframe? I'm trying some remote scripting calling "window.parent.callback" but it seems that the iframe doesn't have any reference to the "outter" document. So anyone knows how does it work? Affonso
by Affonso Loyola at
I've tryed what Martin Franz decribed, setting the: transferDoc.parentWindow.foo = foo; But I cant make it work! Someone successfull on that? Affonso
by Affonso Loyola at
I think iI might not setting the domain rigth on the outter document and in the iframe. I'm sunning my application on localhost. Is that a problem?   Affonso 
by Affonso Loyola at
so,if the iframe is appened to the htmlfile activex object, how does the iframe frame's javascript code call its parent frame's functions?  just like the code "parent.transData('test')" in the iframe.
transferDoc.parentWindow.foo = foo; It works well, but I discover another fatal problem,the "htmlfile" activexobject will timeout after about 30s autolly,And the iframe doesn't output anything.
Interesting, but how do you call functions IN the window that opens the transferDoc FROM the iframe inside the transferDoc ?

I see no logic with this at all:

transferDoc.parentWindow.foo = foo;

by Bench at
incidentally, what would be the equivalent to this:

var transferDoc = new ActiveXObject("htmlfile"); // !?!

for Firefox?

by Bench at
 I don't think there's something equivalent for firefox...
by KooKiz at
Is here anybody who have found out the solution in firefox?
by rick at
 
by alex at
Hi Alex,

It seems that lots of them can't try something new (to them). I've been tracking some of the Dojo Toolkit. It's really amazing and interisting, but currently I understand that dojo uses Ajax to interact with the server. Do you, the Dojo's development team, plan to adopt, port or migrate to "Comet" model? I know Dojo has the Cometd project, but is this a separated project? or will be integrated into dojo's javascript libraries? If so, which version will include it?

Regards, Ivan Garavito

by Ivan Garavito at
Is this the same as the oracle htmlfile object?
by rusty at
In Firefox you don't need to mess with frames as the XmlHttpRequest will return data as it's being loaded and there is no "throbbing" problem.

For IE, has anyone confirmed that you can call code in the parent of the "htmlfile" frame?

Alex, you have comments in the cometd.js code to the effect of "TODO: improve with Gmail fix". Any luck?

The IE iframe issue being solved, how does gmail get around the 2-connections limit? What are the possible approaches for that as it's a common problem in FF and IE?

The obvious is to change the browser behavior. Good luck with that! We need solutions that work now. (http://lists.whatwg.org/pipermail/whatwg-whatwg.org/2006-November/007599.html

by Dok at
This is quite neat, ajax is pretty neat I just wish they would make it simpler, or turn it into a standard so that instead of opening a big xmlhttp request just have like a line or two of code that could send data and recieve data, or have an option to keep an open connection.

Be kinda cool to see if they make web pages in the future be run off of ajax or something similiar so browsers never have to refresh.

Regards.

by Aaron at
See this link for info on how to do this in Firefox/Mozilla:http://meteorserver.org/browser-techniques/
by Jason at
AVG free
I've been searching around for this thing called "Comet" or "HTTP streaming" for the past hour or so, and now I find out it's just a lame hack. Why doesn't someone just give JavaScript a socket object, and then we can just do things in a more straightforward way that makes sense? Geez. Do I have to take the overhead of Java or Flash every time I want to open a normal socket connection?
by Matthew at