Comet (long polling) for all browsers using ScriptCommunicator
There's little information on the web how to implement comet (long polling) so it works across domains and works in all major browsers.
I am sharing my solution that's used to power comet on Plurk and I hope this can save time for anyone that has to implement something similar.
I have pushed ScriptCommunicator on github and this script can do following stuff:
There are different problems associated with long polling:
To solve this we use script tags for communication and this has one big pitfall: you can't easily find out whatever a script is sourced properly - - so error handling using script tags becomes a lot more difficult. ScriptCommunicator adresses these issues and makes communication easy.
It's trivial to source scripts across domains (you simply append the SCRIPT tag to the head or the body). What's not trivial is finding out if the script was sourced properly and handling errors - and I haven't found a solution for this problem on the net. But there is a solution and it works like this:
It's hacky, but it works :-)
How to use it
ScriptCommunicator.callback_called = true;
That's basically it! Visit ScriptCommunicator on github to get the code.
If you are interested in comet check out following amix.dk posts: