Browsers continue to run Javascript after "PageUnload" and the new "PageLoad",

We have the next AJAX jitter. This was implemented in order to be able to execute many (20+) ajax requests for one page without residual time, only because the first X requests took a total of 60 seconds.

RequestThrottler: {
    maximumConcurrentRequests: 3, //default to 3        
    requestQueue: new Array(),
    numberOfRequestCurrentlyProcessing: 0,

    addRequestToQueue: function (currentRequest) {
        var self = this;
        self.requestQueue.push(currentRequest);

        if (self.numberOfRequestCurrentlyProcessing < self.maximumConcurrentRequests) { self.sendNextRequest(); }
    },

    sendNextRequest: function () {
        var self = this;
        if (self.numberOfRequestCurrentlyProcessing >= self.maximumConcurrentRequests) { return; }
        if (self.requestQueue.length === 0) { return; }

        var currentRequest = self.requestQueue.pop();
        self.numberOfRequestCurrentlyProcessing++;
        AJAX.SendAjaxRequest(currentRequest.url, currentRequest.httpMethod, 
            function(data){
                self.numberOfRequestCurrentlyProcessing--;
                currentRequest.onSuccessCallback(data);
                self.sendNextRequest();
            }, 
            function(){
                self.numberOfRequestCurrentlyProcessing--;
                currentRequest.onErrorCallback();
                self.sendNextRequest();
            });
    },

    sendUpdateRequest: function (currentRequest) {
        var self = this;
        self.addRequestToQueue(currentRequest);
    }
}

However, since these requests are in the Javascript queue when a user tries to load a new page, the developer tools display the answers in the NET area of ​​the new page. Our application has a privacy check to prevent this behavior. Is this normal for browsers, or is it some kind of error, or am I doing something wrong?

+4
1

window.onbeforeunload abort ajax-, .

beforeunload unload :

1) beforeunload , unload:

. , Firefox , , , . , , beforeunload.

:

2) beforeunload , unload . , , beforeunload. , , ajax .

window.addEventListener("beforeunload", function (e) {
  var confirmationMessage = "\o/";

  (e || window.event).returnValue = confirmationMessage;     // Gecko and Trident
  return confirmationMessage;                                // Gecko and WebKit
});

:

+4

All Articles