I. Summary
This article summarizes how to enable gzip compression for Web sites that are hosted by IIS, thereby reducing the network transmission size of your Web page and increasing the speed at which users can display pages.
two. Preface.
The knowledge points of this paper are collected from the Internet, mainly from Chinese wiki. Gzip is critical when using YSlow to detect which optimizations are enabled on the Web site. Starting GIP compression will instantly reduce the network transmission size of the page.
three. HTTP Compression overview
HTTP compression is a way to transfer compressed text content between a Web server and a browser. HTTP compression uses a common compression algorithm such as gzip compression HTML, JavaScript, or CSS files. The biggest benefit of compression is that it reduces the amount of data transferred by the network, thereby increasing the access speed of the client browser. Of course, it will also add a little bit of server burden. Gzip is a more common kind of HTTP compression algorithm.
Four. HTTP Compression working principle
The Web server works with HTTP compression as follows:
After the 1.WEB server receives the HTTP request from the browser, check to see if the browser supports HTTP compression;
In the HTTP header where the user's browser sends the request, the "accept-encoding:gzip, deflate" parameter indicates that the gzip and deflate two compression algorithms are supported.
2. If the browser supports HTTP compression, the Web server checks the suffix name of the request file;
Both the static file and the dynamic file suffix startup need to be set in MetaBase.xml.
Static files need to be set: HcFileExtensions Metabase Property (click Jump to MSDN Description)
Dynamic files need to be set: HcScriptFileExtensions Metabase Property (click Jump to MSDN Description)
3. If the request file is a static file such as HTML, CSS, and the file suffix is compressed, the Web server checks the compressed buffer directory to see if the requested file has the latest compressed file;
4. If the compressed file of the requested file does not exist, the Web server returns the uncompressed request file to the browser and holds the compressed file of the request file in the compressed buffer directory;
5. If the latest compressed file of the request file already exists, then directly returns the compressed file of the request file;
6. If the request file is an ASPX dynamic file and the file suffix has compression enabled, the Web server dynamically compresses the content and returns to the browser, and the compressed content is not stored in the compressed cache directory.
Five. Enable HTTP compression in IIS
IIS does not support HTTP compression by default, and requires a simple configuration
1. Open Internet Information Services (IIS) Manager, right-click Web site-> properties, and select Services. In the HTTP Compression box, select Compress application files and compress static files, and set the maximum limit for temporary directories and temporary directories as needed;
2. Reminder: After testing this step on my machine has no effect, you can ignore.
in Internet Information Services (IIS) Manager, right-click the Web service extension "->" to add a new Web service extension ..., and in the new Web service Extension box, enter the extension "HTTP Compression" , add "required files" as C:\WINDOWS\system32\inetsrv\gzip.dll, where the WINDOWS system directory may be different depending on your installation, and select "Set extension status to allow";
3. Use a text editor to open C:\Windows\System32\inetsrv\MetaBase.xml (recommended to back up first),
Find location = "/lm/w3svc/filters/compression/gzip used to set gzip compression,
Find location = "/lm/w3svc/filters/compression/deflate" to set deflate compression.
The top two nodes are next to each other. And the properties set are the same.
If you need to compress a dynamic file, set HcDoDynamicCompression to TRUE, and in hcscriptfileextensions, add the dynamic file suffix name, such as ASPX, that you want to compress, and if you need to compress the static file, Set HcDoStaticCompression and HcDoOnDemandCompression to "TRUE" and add the static file suffix names you want to compress in hcfileextensions, such as XML, CSS, etc. HcDynamicCompressionLevel and HcOnDemandCompLevel indicate the desired compression rate, with a value of 0-10, and a default of 0.
HcDynamicCompressionLevel attribute Description: HcDynamicCompressionLevel Metabase Property
HcOnDemandCompLevel attribute Description: HcOnDemandCompLevel Metabase Property
Description: These two property values are generally recommended to be set to 9, with the best price/performance. But on my Window Server 2003, the compression rate is the same size as the jquery and jquery ui two files (58k/188k). (20k/45k).
Here's my example:
Copy Code code as follows:
<iiscompressionscheme Location = "/lm/w3svc/filters/compression/deflate"
Hccompressiondll= "%windir%\system32\inetsrv\gzip.dll"
hccreateflags= "0"
hcdodynamiccompression= "TRUE"
hcdoondemandcompression= "TRUE"
Hcdostaticcompression= "true"
Hcdynamiccompressionlevel= "9"
hcfileextensions= "htm
Html
Txt
Js
Css
Swf
xml
Hcondemandcomplevel= "9"
hcpriority= "1"
hcscriptfileextensions= "ASP aspx
Dll
Exe
>
</IIsCompressionScheme>
<iiscompressionscheme Location = "/lm/w3svc/filters/compression/gzip"
Hccompressiondll= "%windir%\system32\inetsrv\gzip.dll"
hccreateflags= "1"
hcdodynamiccompression= "TRUE"
hcdoondemandcompression= "TRUE"
Hcdostaticcompression= "true"
Hcdynamiccompressionlevel= "9"
hcfileextensions= "htm
Html
Txt
Js
Css
Swf
xml
Hcondemandcomplevel= "9"
hcpriority= "1"
hcscriptfileextensions= "ASP aspx
Dll
Exe
>
</IIsCompressionScheme>
4. Save the MetaBase.xml file after editing; If the file cannot be saved, it may be in use by IIS. Open the "Start"-> "Administrative Tools"-> "services", Stop the "IIS Admin service", you can save;
5. Finally, restart IIS. You can verify the results on the HTTP compression test site. In jquery, for example, the core class libraries and UI class libraries were 57k and 188k in size, respectively, 20k and 45k after compression:
We passed the HTTP header: Content-encoding:gzip property to determine that the data returned is enabled for gzip compression:
Using yslow detection, gzip compression is rated B when only static file compression is started:
When dynamic file compression is started at the same time, gzip compression is rated A:
Six. Important Summary
1. To stop the IIS Admin Service when you modify the MetaBase.xml file Service. Otherwise, it cannot be saved.
2. Static compression and dynamic compression rates are best set to 9.
3. Step 2 above, even without adding a Web service extension effect, is the same.
4. The compression rate setting does not work for JS files and is always the same size after compression.
5. The picture file does not change even if the gzip compression size is enabled.
Seven. Summary
This article summarizes how to enable gzip compression in IIS. In the project of six months ago I enabled Gzip for the website, today finishing this article mainly in order to tidy up their knowledge in order to later forget the review. In addition, the CDN provided by the ChinaCache company also has gzip compression enabled.
Enable IIS6 gzip, improve Web site opening speed, reduce bandwidth consumption
use Vbs+cmd, fully automatic implementation, if a thing is not commonly used, but very useful, or to make him a health-style, so even forget also indifferent, anyway can be a 100% success.
Http://xiazai.jb51.net/201101/tools/IIS6-SET-GZIP.rar