What is gzip? What are the advantages? How can I enable gzip?

Source: Internet
Author: User
Tags metabase

1. What is gzip?
A: gzip was first created by Jean-Loup gailly and Mark Adler for File compression in UNIX systems. We often use files suffixed with .gz in linux, which are in GZIP format. Nowadays, it has become a widely used data compression format on the Internet, or a file format. Gzip encoding on HTTP is a technology used to improve the performance of Web applications. Large-Traffic web sites often use gzip compression technology to make users feel faster. This generally refers to a function installed on the WWW server. When someone visits the website on this server, this function in the server compresses the webpage content and then transmits it to the visiting Computer Browser for display. generally, the plain text content can be compressed to 40% of the original size. in this way, the transmission is faster, and the result is that you click the URL and it will be displayed soon. of course, this will also increase the server load.
This function module is installed on servers.

2. What are the advantages of gzip?
A: After Gzip is enabled, the data output to the user's browser will be compressed to reduce the amount of data transmitted over the network and increase the browsing speed.

3. How to enable the gizp compression function of IIS:
A: First, if you need to compress static files (HTML), you need to create a directory on the hard disk and give it the write permission of the user "IUSR _ machine name. It is not required to compress dynamic files (PHP, ASP, and aspx), because the pages are dynamically generated every time, so you can discard them after compression. In the IIS manager, right-click the website and choose "properties". The website is not the following site, but the whole website. Go to the "service" tab and choose to enable dynamic content compression and static content compression. Select the Server Extension under the website and create a new server extension. The name does not matter. The path of the file to be added below is: c: \ windows \ system32 \ inetsrv \ gzip. dll, and then enable this extension. Static content can be compressed at this time, but for dynamic content, the aspx file is not within the compression range. Because the default file that can be compressed does not have this extension. On the management interface, you cannot find a place where the extension can be added. At this time, you can only modify its configuration file. There is a metabase under c: \ windows \ system32 \ inetsrv. XML file. You can open it in notepad and find the iiscompressionscheme. There are three segments with the same name, namely deflate, Gzip, and parameters. You do not need to worry about the third segment, the first two paragraphs have basically the same parameters. Add a line of aspx under the parameters hcscriptfileextensions. If you have other dynamic programs to compress, add them here. Change hcdynamiccompressionlevel to 9 (0-10, 9 is the most cost-effective ). Then you need to restart the IIS service to realize the compression speed.

Enable gzip compression for IIS or Apache

First, let's take a look at gzip. Gzip is short for GNU zip. It is a File compression program of GNU Free Software and is often used to represent the GZIP file format. Software authors are Jean-loupgailly and Mark Adler. The first public release was made in October 31, 1992. The version number is 0.1, and the current stable version is 1.2.4.

Gzip can greatly accelerate the website. sometimes the compression ratio is as high as 80%. After a recent test, there are at least 40% or more, which is quite good. in Versions later than apache2, the module name is not gzip, but mod_deflate

  1. Enable gzip in Apache

To enable gzip, you must open the following two modules.

Loadmodule headers_module modules/mod_headers.so

Loadmodule deflate_module modules/mod_deflate.so

Set the compression ratio. The value ranges from 1 (minimum) to 9 (maximum). It is not recommended to set it too high. Although there is a high compression rate, it occupies more CPU resources.

Deflatecompressionlevel 3

Addoutputfilter deflate HTML XML PHP JS CSS

<Location/>

Setoutputfilter deflate

Browsermatch ^ Mozilla/4 gzip-only-text/html

Browsermatch ^ Mozilla/4 \. 0 [678] No-Gzip

Browsermatch \ bmsie! No-gzip! Gzip-only-text/html

Setenvifnocase request_uri \\.(? : GIF | jpe? G | PNG) $ no-gzip dont-vary

Setenvifnocase request_uri .(? : Exe | T? GZ | zip | bz2 | sit | RAR) $ no-gzip dont-vary

Setenvifnocase request_uri .(? : PDF | mov | Avi | MP3 | MP4 | RM) $ no-gzip dont-vary

Header append vary User-Agent Env =! Dont-vary # proxy settings

</Location>

The following two test websites

Http://www.whatsmyip.org/mod_gzip_test/

Http://www.gidnetwork.com/tools/gzip-test.php

Test data on CSS

Original size: 44 KB

Gzipped size: 10 KB

Data savings: 77.27%

Test data JS

Original size: 6 KB

Gzipped size: 2 kb

Data savings: 66.67%

Test data PHP

Original size: 62 KB

Gzipped size: 15 KB

Data savings: 75.81%

The above is just a few random data. As you can see, the size of the file is much smaller after gzip compression is used.

In addition, the processing of squid on Gzip

In squid, only one copy of the cache is reserved for the same URL. If different browsers (whether compression is supported) are frequently accessed alternately, for example, for a cache destination, an HTTP/1.0 request may force squid to update its cache. However, another HTTP/1.1 request will cause squid to update the cache again. In this way, the Squid cache data needs to be updated frequently, which greatly reduces the cache hit rate.

But fortunately, browsers that do not support compression in the real environment are rare, so the cache hit rate is very limited.

The module is mod_gzip. It compresses Apache pages by using the same compression algorithm as gzip. If possible, it can compress the pages into one of ten copies of the original size. If a 10 k page is uploaded to 1 K, this is 10 times faster. Of course, the general web page can only be 3-6 times. That's pretty good. Right. Even a large website like Google uses this technology. Are you not keeping up with me?

I will tell you how to install this kind of things in three steps: 1. Download, 2. modify configurations, 3. Test.

  Download

Download mod_gzip.c from the http://www.remotecommunications.com/apache/mod_gzip and install its patch.

  Install and configure

Put mod_gzip in your Apache source code directory, and create a mod_gzip directory. If you need a patch (for version 1.3.17.la), run the following command:

Patch mod_gizp.c

Select dynamic DSO or static compilation to Apache in configuration as needed. In README, how to handle it is clearly stated, such as-add-module = mod_gzip.c, make, make install, and so on. I will not talk about it here.

Add the following configuration to the end of httpd. conf.

# Mod_gzip Configuration

Mod_gzip_on Yes

Mod_gzip_minimum_file_size 1002

Mod_gzip_maximum_file_size 0

Mod_gzip_maximum_inmem_size 60000

Mod_gzip_item_include mime "application/X-httpd-PHP"

Mod_gzip_item_include mime text /*

Mod_gzip_item_include mime "httpd/Unix-directory"

Mod_gzip_dechunk Yes

Mod_gzip_temp_dir "/tmp"

Mod_gzip_keep_workfiles No

Mod_gzip_item_include File ". php3 $"

Mod_gzip_item_include File ". txt $"

Mod_gzip_item_include File ". html $"

Mod_gzip_item_exclude File ". CSS $"

Mod_gzip_item_exclude File ". js $"

Run

... /Bin/apachectl configtest Ensure that the configuration is modified correctly.

Use the apachectl restart command to restart the service.

  Modify, test

Before the announcement, we should test the habit of being a good programmer. To minimize the impact on user browsing, we can use the new Apache driver on port 8080 or use commands to control the directory where mod_gzip works, instead of using mod_gzip all at once.

The usage is as follows:

Mod_gzip Configuration

If there is no problem, you can make your users very happy to find that the 'xx website is so fast now. '

Mod_gzip is amazing. A large k HTML document can be uploaded to the user end as long as 12 K. The more you use this technology, the more high your users will be impressed with your website. However, there must be some loss. Because decompression is performed on the client, the effect has something to do with the user's browser.

  2. Enable gzip in IIS

The modern browsers IE6 and Firefox both support the client gzip. That is to say, before the webpage on the server is transmitted, Gzip compression is used before it is transmitted to the client. After receiving the webpage, the client is decompressed and displayed by the browser, in this way, although the CPU usage of some servers and clients is slightly occupied, the bandwidth utilization is higher. For plain text, the compression ratio is considerable. If each user saves 50% of the bandwidth, the bandwidth you lease will be able to serve customers more than doubled.

IIS6 has built-in support for gzip compression. Unfortunately, there is no better management interface. It takes some effort to enable this option.

First, if you need to compress static files (HTML), you need to create a directory on the hard disk and give it the write permission of the user "IUSR _ machine name. It is not required to compress dynamic files (PHP, ASP, and aspx), because the pages are dynamically generated every time, so you can discard them after compression. In the IIS manager, right-click the website and choose "properties". The website is not the following site, but the whole website. Go to the "service" tab and choose to enable dynamic content compression and static content compression.

Select the Server Extension under the website and create a new server extension. The name does not matter. The path of the file to be added below is:

C: \ windows \ system32 \ inetsrv \ gzip. dll and enable this extension.

Static content can be compressed at this time, but for dynamic content, the aspx file is not within the compression range. Because the default file that can be compressed does not have this extension. On the management interface, you cannot find a place where the extension can be added. At this time, you can only modify its configuration file.

There is a metabase under c: \ windows \ system32 \ inetsrv. XML file. You can open it in notepad and find the iiscompressionscheme. There are three segments with the same name, namely deflate, Gzip, and parameters. You do not need to worry about the third segment, the first two paragraphs have basically the same parameters. Add a line of aspx under the parameters hcscriptfileextensions. If you have other dynamic programs to compress, add them here. Change hcdynamiccompressionlevel to 9 (0-10, 9 is the most cost-effective ).

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.