Imagine in application composed of several different widgets. When an event is fired, the widgets clear out their current data, execute an AJAX request, then put in the new information when the response comes back.
The following is a simplified example of what happens when that event is fired:
for (var i = 0; i < 10; i++) {
// Do an AJAX post
$.ajax(document.location.href, {
data: {
name: ‘Zach Gardner’
},
method: ‘POST’
});
// Do some expensive DOM stuff
for (var j = 0; j < 100; j++) {
var el = document.createElement(‘div’);
document.body.appendChild(el);
for (var k = 0; k < 100; k++) {
var child = document.createElement(‘div’);
el.appendChild(child);
el.removeChild(child);
}
}
}
Here is a JSFiddle of the code above
If you open up Fiddler, and run it in Chrome, you'll notice the AJAX requests complete rather quickly.
(source: zgardner.us)
But if you do the same thing in IE (tested in 10, 11, 12 preview), you'll notice that the requests take much longer:
(source: zgardner.us)
What we've found is that IE will create the request when jQuery executes a call to the xhr's send method. But it holds onto the request until the call stack has been emptied.
(source: zgardner.us)
Notice the significant lag between ClientBeginRequest and ClientDoneRequest. We've found that ClientDoneRequest is always within a few milliseconds of the thread ending.
This only happens for POST AJAX requests. The ClientBeginRequest and ClientDoneRequest for GETs are always within a few milliseconds of each other.
Also, note that this problem also shows up with IE's Dev Tools:
(source: zgardner.us)
If you inspect an individual request, you can the second Start, which is when it sends the body of the request, took 4.32 seconds:
(source: zgardner.us)
Why is this happening?
See my blog post for a more detailed explanation.