HTTP protocol analysis series (9) ------ http protocol and content compression

Source: Internet
Author: User
: This article mainly introduces the HTTP protocol analysis series (9) ------ http protocol and content compression. For more information about PHP tutorials, see. Observe that we open a news article in section 163 and see the following header information. the following response header information is displayed. Note that Content-Length


At the same time, right-click to save the source code and save the file size.


Thought: Content-Length represents the Length of the returned body in the previous learning.

But why is the returned body length different from the content-length?

The reason is that the Content-Encoding: gzip response header is in effect.

Principle: in order to improve the transmission speed of webpages over the network, the server compresses the subject information. For example, common gzip compression, deflate compression, compress compression, and sdch compression being pushed by google chrome.

The compression process is as follows:


The reason for this problem is that the server compresses the page. the content-length is the length after "compression ".

How to enable the compression function in apache?

1. enable the deflate module or gzip module.

2. write the following code in the conf file:

3. Why compression by specifying the file type?

A: compression also consumes CPU resources. images, movies, videos, and other files have poor compression performance.

It is generally a compressed text file.

 
  DeflateCompressionLevel 6AddOutputFilterByType DEFLATE text/plainAddOutputFilterByType DEFLATE text/htmlAddOutputFilterByType DEFLATE text/xmlAddOutputFilterByType DEFLATE text/cssAddOutputFilterByType DEFLATE text/javascriptAddOutputFilterByType DEFLATE application/xhtml+xmlAddOutputFilterByType DEFLATE application/xmlAddOutputFilterByType DEFLATE application/rss+xmlAddOutputFilterByType DEFLATE application/atom_xmlAddOutputFilterByType DEFLATE application/x-javascriptAddOutputFilterByType DEFLATE application/x-httpd-phpAddOutputFilterByType DEFLATE image/svg+xml
 

Q: How does the server know that our browser supports gzip?

A: The client allows sending an accept-Encoding header to negotiate with the server.

This example shows the three types of chrome

Firefox supports only two compression methods.

Tips: when collecting data, you can choose not to send the Accept-Encoding information. in this way, the source code is directly collected. of course, you can also collect gzip (to increase the speed) and decompress the content with gzip.


The above introduces the HTTP protocol analysis series (9) ------ http protocol and content compression, including content, hope to be helpful to friends who are interested in PHP tutorials.

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.