: 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.