Q:

Google Chrome slows on Ajax requests when disconnected

I am making polling requests to a server using Angulars $http.post. However if the server is shutdown, the clients browser (Google Chrome) becomes very slow, on Firefox however it runs fine. I cannot reproduce this on my dev machine, maybe due to it being more powerful, but I did also notice a difference between the two machines. The clients browser reports ERR_CONNECTION_RESET, while mine reports ERR_CONNECTION_REFUSED. I am not sure if this makes any difference.
The code itself does not do much:
var update = function () {
    $http.post(url)
        .success(onSuccess)
        .error(onError);
};

var onError = function () {
    $rootScope.errors = true;
    $timeout(update, pollInterval * 2);
};

var onSuccess = function (data) {
    _data = data;
    $rootScope.$broadcast('dataUpdated');
    $rootScope.errors = false;
    $timeout(update, pollInterval);
};

I cannot find any reason why this would slow down Chrome only on disconnect. Returning a 5xx http code works fine, so it should not be related to the onError function either. Google Chrome version is 33.0.1750.

A:

It looks like your code waits for the response from the server, and then does stuff given its succeeded or failed. So, that doesn't really point to a performance issue, it just says that things don't happen until you hear back from the server – which takes a lot of time since the server is shut down and its a connection reset (after waiting for a response) rather than an immediate connection refused. Hence the difference.
I'd suggest you use timeouts with your $http when working in a situation where the server might be shut down. Here's the doc.

