As JavaScript developers, we are used to years of hacks, as we try to push forward without browsers updating and helping us out. We are so stuck in this pragmatic thinking that we sometimes forget to pick our heads up.
Kris Zyp has taken some time to think about Comet, and instead of thinking about the next good hack, he takes that step back and dreams:
What if I had commit privileges on all the major browsers, the competence to add functionality in all the code bases, and wanted to add native Comet support in a form that was easily accessible to developers?
He ends up with a proposal that adds to good ole XHR:
With only a few simple XMLHttpRequest API additions, Comet communication could be realized with a native implementation that supports fast and efficient standards-based two-way asynchronous communication, with true server-delivered HTTP streaming and simple subscription requests, with the added benefit of client-delivered streaming and cached resource until updated capability. Developers could create Comet applications with a standard API without hacks. Communication could be standards-based, allowing current servers to easily implement the necessary features to handle communication.
It would look something like this:
-
-
var cometXHR = new XMLHttpRequest;
-
cometXHR.open('POST','comet',true);
-
-
var xhr1 = new XMLHttpRequest;
-
cometXHR.addHttpChunk(xhr1);
-
xhr1.onreadystatechange=function(){...}
-
xhr.open('GET','/ticker1',true);
-
xhr.send();
-
-
var xhr2 = new XMLHttpRequest;
-
cometXHR.addHttpChunk(xhr2);
-
xhr2.onreadystatechange=function(){...}
-
xhr.open('GET','/ticker2',true);
-
xhr.send();
-
Kris gets into many of the details, and makes me with that someone would implement this as a Google Gear, so it could get pushed into the fabric of the Web by being on all browsers.
