I have developed a solution that relies on an AJAX call to retrieve information and update the client page every 10 seconds. This is working fine, but I am concerned at the scalability of the code, given the number and length of headers being passed from client to server and back again. I have removed a number of redundant headers on the server side, mostly ASP.NET-related, and now I’m attempting to cut down on the headers coming from the client.
The browser used by my company is IE (version 6, to be upgraded to 7 soon). This is an approximation of my current code:
var xmlHTTP = new ActiveXObject('Microsoft.XMLHTTP'); xmlHTTP.onreadystatechange = function() { if ((xmlHTTP.readyState == 4) && (xmlHTTP.status == 200)) { myCallbackFunction(xmlHTTP); } }; xmlHTTP.open('GET', 'myUrl.aspx'); try { xmlHTTP.setRequestHeader('User-Agent', '.'); xmlHTTP.setRequestHeader('Accept', '.'); xmlHTTP.setRequestHeader('Accept-Language', '.'); xmlHTTP.setRequestHeader('Content-Type', '.'); } catch(e) {} xmlHTTP.send();
Although I’ve read that it’s possible to clear some of these headers, I haven’t found a way of doing it that works in IE6. Setting them to null results in a Type Mismatch exception, so I’ve ended up just replacing them with ‘.’ for the time being. Is there another way of clearing them or an alternative method of reducing the submitted HTTP headers?
Also, there seems to be no way of replacing or shortening the ‘Referrer’ header at all.
According to the WD spec
That is, you could only add headers, not replace them.
This doesn’t completely match current browser behaviour, but it may be where browsers will be headed, in which case any efforts on this front are a waste of time in the long term. In any case current browser behaviour with setting headers is very varied and generally can’t be relied upon.
That wouldn’t surprise me, given that some people misguidedly use ‘Referer’ [sic] as an access-control mechanism.
You could try to make sure that the current page URL wasn’t excessively long, but to be honest all this smells of premature optimisation to me. Whatever you do your request is going to fit within one IP packet, so there’s not gonig to be a big visible performance difference.
It may be worthwhile for Mibbit (as mentioned on the blog you linked) to try this stuff, because Mibbit draws a quite staggering amount of traffic, but for a simple company-wide application I don’t think the cross-browser-and-proxy-testing-burden:end-user-benefit ratio of messing with the headers is worth it.