Free from the shackles of the browser (5)

Source: Internet
Author: User

Remember "asp.net AJAX Under the Hood secrets"? This is the only article I've recommended on my blog (but it's more likely to be a whim). In this article, Omar Al Zabir presents some of his experiences in using ASP.net ajax. One of the things that is mentioned here is that Browsers do not respond when the than two calls in queue. To put it simply, in IE, if more than 22 connections are established in the connection state, but no connection succeeds (no problem after the connection succeeds, even when the data is transferred), the browser stops responding to other actions, such as clicking on the hyperlink for page jumps, The browser will not respond to user actions again until there are no more connections than the two connections you are trying.

This problem generally requires 3 conditions:

Too many connections are established at the same time, for example, there are many modules on a portal that request server-side data at the same time.

The response is slow, it takes a long time to initiate a connection from the browser to a server-side response connection.

Use IE browser, whether IE6 or IE7 will this problem, and Firefox is all right.

In the IE7 incredibly still have this bug, it is really sad to laugh and cry. But we have to solve this problem, don't we?

Write code to maintain a queue

As with the article asp.net AJAX Under the Hood Secrets, the easiest solution is to write code to maintain a queue. This queue is very easy to write and the code is as follows:

Requestqueue.js

if (!window.Global)
{
  window.Global = new Object();
}
Global._RequestQueue = function()
{
  this._requestDelegateQueue = new Array();

  this._requestInProgress = 0;

  this._maxConcurrentRequest = 2;
}
Global._RequestQueue.prototype =
{
  enqueueRequestDelegate : function(requestDelegate)
  {
    this._requestDelegateQueue.push(requestDelegate);
    this._request();
  },

  next : function()
  {
    this._requestInProgress --;
    this._request();
  },

  _request : function()
  {
    if (this._requestDelegateQueue.length <= 0) return;
    if (this._requestInProgress >= this._maxConcurrentRequest) return;

    this._requestInProgress ++;
    var requestDelegate = this._requestDelegateQueue.shift();
    requestDelegate.call(null);
  }
}
Global.RequestQueue = new Global._RequestQueue();

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.