HTTP protocol 3 compression--turn

Source: Internet
Author: User

the difference between HTTP content encoding and HTTP compression

HTTP compression, in the HTTP protocol, is actually a kind of content encoding.

In the HTTP protocol, the content (that is, the body part) can be encoded, which can be encoded using gzip. So as to achieve the purpose of compression. You can also use other encodings to scramble or encrypt content to prevent unauthorized third parties from seeing the contents of the document. So we say that HTTP compression, in fact, is a kind of HTTP content encoding. So let's not confuse the two concepts of HTTP compression and HTTP content encoding.

the process of HTTP compression

1. The browser sends an HTTP request to the Web server with Accept-encoding:gzip, deflate in request. (Tell the server that the browser supports gzip compression)

2. After the Web server receives the request, it generates the original response, which has the original Content-type and Content-length.

3. The Web server uses gzip to encode the response, with Content-type and content-length (compressed size) in the header, and Content-encoding:gzip added. Then send the response to the browser.

4. After the browser receives the response, the response is decoded according to the Content-encoding:gzip. After you get to the original response, the page is then displayed.


Such as:

Example: Fiddler observing HTTP Compression

Seeing is believing, let's look at a practical example, and I found that the blog park was using gzip compression.

The use of Fiddler can be clearly seen.

In Fiddler, you have to manually go to decode each time.  Too troublesome. Click on the "Decode" button on the toolbar to automatically Decode.

content Encoding Type

HTTP defines a number of standard content encoding types, and allows for the addition of more encodings in the form of extensions.

The content-encoding header uses these standardized codes to illustrate the algorithm used in encoding

Content-encoding value

Gzip indicates that the entity uses the GNU ZIP code

Compress indicates that the entity uses UNIX's file compression program

Deflate indicates that the entity is compressed in zlib format.

The identity indicates that the entity is not encoded. When there is no content-encoding header, it is implied that the situation

gzip, compress, and deflate codes are lossless compression algorithms that reduce the size of transmitted messages without causing loss of information. Gzip is usually the most efficient and most widely used.

Advantages of compression

HTTP compression can compress plain text to 40% of the original content, saving 60% of data transfer.

Example: Blog home before compression is: 46124 bytes.     After compression is: 16368bytes.  Only the original 35%. 65% savings in data transfer, which greatly improves performance

There is a picture for proof.

The disadvantages of gzip

JPEG files with gzip compression are not good enough.

how gzip is compressed

In short, gzip compression is to find similar strings in a text file and temporarily replace them to make the entire file smaller. This form of compression works well for the web because HTML and CSS files often contain a large number of duplicate strings, such as spaces, tags.

HTTP response can be compressed, HTTP request can also be compressed

The browser is not compressed for request. However, some HTTP programs encode the request when it is sent. Such as.

HTTP protocol 3 compression--turn

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.