Despite being a geek, I don't actually know all that much about HTML, CSS, or all that webby stuff. The election thing was my first ever applet, and I've never known JavaScript before yesterday. But I've been thinking more about AJAX and the things you can do with it, and I think it's time I learned that stuff, because it's super cool and will be super extra hyper ace cool once SVG gets added to the mix. Here's something I've been trying today.
Because web clients generally insist on initiating all requests, the only way to keep a page up to date is usually to poll. Poll too slowly and you don't hear about changes until much later; poll too fast and you load the whole system unnecessarily.
It turns out that with AJAX you have a third option. I've just implemented a simple Web-based "tail" program with it - go to a Web page, and it shows you the tail of a file, updated in real time. The trick is basically to implement a hook in your CGI script so that if you have nothing to report, wait until you do before returning. As soon as you do have something, return it and close the connection. It's easy to be robust against timeouts so that if the connection gets closed early the client will just open it again and wait some more. The result is that the "polling" load is very low because the "polling interval" is as long as your timeouts, but once news arrives the client gets to hear about it very fast because it's hanging waiting for it.
Next, a boardgame. Or a Web-based IRC client. Or maybe a terminal emulator...
no subject
Date: 2005-05-16 11:43 pm (UTC)http://www.danga.com:8080/misc/jsdraw/xmlhttp.html
The server is Perlbal, with a plugin that keeps a long-lived (forever) HTTP connection open sending chunked content when new data arrives.
No polling.
no subject
Date: 2005-05-17 07:10 am (UTC)no subject
Date: 2005-05-17 07:23 am (UTC)http://danga.com/misc/Jslab.pm.txt
It doesn't consume a process or a thread... it's all async/event-based, so don't do anything that'll stall the event loop (the one server process) for too long.
no subject
Date: 2005-05-17 12:05 am (UTC)no subject
Date: 2005-05-17 02:21 am (UTC)no subject
Date: 2005-05-17 06:25 am (UTC)no subject
Date: 2005-05-17 06:53 am (UTC)no subject
Date: 2005-05-17 07:24 am (UTC)no subject
Date: 2005-05-18 10:03 am (UTC)http://www.danga.com/openid/
I thought it might be interesting to you, after our old discussions about identity verification to third party sites.
no subject
Date: 2005-05-19 03:49 pm (UTC)