Optimize Website Design (16): Use the get Method for Ajax requests

Source: Internet
Author: User
Preface

The optimization of website design is a big topic. There are some general principles and some suggestions for different development platforms. This research has never been stopped, and I have shared this topic on different occasions.

As a general principle, Yahoo's team of engineers once provided 35 best practices. For this list, seeBest practices for speeding up your web siteHttp://developer.yahoo.com/performance/rules.html, at the same time, they also integrated a corresponding test tool yslow http://developer.yahoo.com/yslow/

I strongly recommend that all website developers learn these best practices and apply them based on their actual projects. In the next period of time, I will combine the ASP. NET development platform and use a seriesArticleTo help you better understand and use these principles.

Preparations

Prepare the following development environment and tools to follow me for subsequent learning.

    1. Google Chrome or Firefox, and install the yslow extension component. Please note that this component is provided by Yahoo, but there is no version for IE currently.
      1. Https://chrome.google.com/webstore/detail/yslow/ninejjcohidippngpapiilnmkgllmakh
      2. Https://addons.mozilla.org/en-US/firefox/addon/yslow/
      3. You should have some knowledge about the developer tools of these browsers. You can call up this tool by pressing F12.
    2. VISAUL studio 2010 SP1 or later, Visual Studio 2012 is recommended
      1. Http://www.microsoft.com/visualstudio/eng/downloads
    3. You need to have a good understanding of the basic development process and core technologies of ASP. NET. This series of articles is difficult to popularize basic knowledge.
Topics to be discussed in this article

I will discuss the 16th principle in this article: Use get for Ajax requests (use the get Method for Ajax requests)

I have discussed Ajax in a previous article (optimizing Website Design (14th): Making Ajax calls use cache features as much as possible). In that article, we have discussed the post and get methods. Ajax uses different caching features.

    1. POST request, cannot use Client Cache
    2. GET requests can be cached by the client (and as long as the address is the same, it will always use the client cache)

In this sense, using get has a better performance than post. (Because it reduces the number of requests and data duplication ).

At the same time, this principle also mentions another valuable information:

When usingXMLHttpRequest, Post is implemented in the browsers as a two-step process: sending the headers first, then sending data. so it's best to use get, which only takes one TCP packet to send (unless you have a lot of cookies ).

When using XMLHttpRequest (currently Ajax is implemented based on it), if the method is post, the browser will actually send the header information in two steps, then send the data again (because it is a browser behavior, I cannot provide a verification method at present ). However, if get is used, only one TCP packet is sent (unless there are a large number of cookies), which can undoubtedly improve the performance.

[Note] the size of a TCP packet is about 1452 bytes.

Of course, in real projects, get is not always used. For example, there may be restrictions on the length:

The maximum URL Length in IE is 2 K, So if you send more than 2 k Data you might not be able to use get.

If you use get, you also need to consider version updates. I have mentioned this in optimizing Website Design (14th): Making Ajax calls take advantage of cache features as much as possible.

 

In fact, in addition to post, get, the HTTP protocol also defines some other methods, some of them are particularly useful, interested friends can refer to the http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

Related Article

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.