When we send an XMLHttpRequest, we always hundreds of extra bytes with it. In a normal usage it is good. But when building applications that needs speed, this is not good for reliablility.
function update(){
var xhr = getXMLHttp(); // Normal catch handler for XHR
xhr.open("POST", "update.php?r=" + "&chatvslog=" + user, true);
xhr.send();
window.setTimeout("update();",300);
}
The request over does take all the way from 170 to 360ms to send. The problem is that I need this job done faster.
Is there a way of improving my XMLHttpRequest or doing this another way?
Polling is a bad workaround that does the job in a small scalle but is not efficient and ugly to implement.
Modern browsers support WebSockets as a much better way to allow bidirectional communication. With something such as node.js’ Socket.IO you can even use a high-level WebSocket abstraction layer that falls back to whatever is available in the browser – it can use WebSockets (preferred) and techniques such as Flash sockets, AJAX long-polling or JSONp long-polling without you having to care about what’s used.