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.
- 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.
- Https://chrome.google.com/webstore/detail/yslow/ninejjcohidippngpapiilnmkgllmakh
- Https://addons.mozilla.org/en-US/firefox/addon/yslow/
- You should have some knowledge about the developer tools of these browsers. You can call up this tool by pressing F12.
- VISAUL studio 2010 SP1 or later, Visual Studio 2012 is recommended
- Http://www.microsoft.com/visualstudio/eng/downloads
- 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.
- POST request, cannot use Client Cache
- 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