Free from the shackles of the browser (6)

Source: Internet
Author: User

The title is a bit of a bluff, because it spans only subdomains.

The story goes like this, or that personal portal site. One of the features is RSS subscriptions, where each subscription appears as a module on the page. If a user subscribes to more RSS, all the RSS modules will start loading when the page is opened, which can take more than 10 seconds or more to complete. At this point, if the user needs to do other AJAX operations-such as saving page settings-then the long wait is inevitable, who let the browser for the same domain name can only have two connections? But this is not a good user experience, so what do we need to do?

The first approach might be easier to think of, we can write our own code to maintain a priority Queue, attach a "priority" message for each request, so that we can take the important request out of the first place. This will solve the user's waiting problem to some extent. Unfortunately, this method still cannot break through the limit of two connections. So the second approach, we have to try to break through the limit of two connections. If you can make an AJAX request to another domain name, can you avoid important requests being blocked by a large number of requests?

Let's look at it from the beginning, 1.1 points to solve the problem.

Blocked Ajax requests

Let's confirm the blocking of the request first. We use the following code:

Three consecutive requests launched

function simpleRequest()
{
  var request = new XMLHttpRequest();
  request.open("POST", "Script.ashx");
  request.send(null);
}
function threeRequests()
{
  simpleRequest();
  simpleRequest();
  simpleRequest();
}

3 consecutive requests for the same domain name are issued when the threerequests is executed, or the blocking effect is viewed through a statistical chart (Figure 11):

Figure 11: The last request was blocked by the top two requests

Each request takes 1.5 seconds to be spent. It is clear that the third request must wait until the end of the first request to execute, so that a total of more than 3 seconds is required for execution to complete. This is the situation that we want to change.

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.