/Files/wucg/IIS6-SET-GZIP.rar
Original
Http://jiaxu615.blog.163.com/blog/static/13463443720101343125753/
I. Summary
This article summarizes how to enable gzip compression for websites hosted by IIS to reduce the network transmission size of webpages and increase the page display speed.
Ii. preface.
The knowledge points in this article are collected from the Internet, mainly from the Chinese wiki. gzip is critical when yslow is used to check which optimizations are enabled on the website. starting GIP compression will immediately reduce the page's network transmission size.
Iii. Http compression Overview
HTTP compression is used to transfer compressed text content between web servers and browsers. HTTP compression uses common compression algorithms such as gzip to compress HTML, JavaScript, or CSS files. The biggest advantage of compression is that it reduces the amount of data transmitted over the network and increases the access speed of the client browser. Of course, it also adds a little load on the server. Gzip is a common HTTP compression algorithm.
Iv. How HTTP compression works
How the Web server processes HTTP compression is as follows:
1. After receiving the HTTP request from the browser, the web server checks whether the browser supports HTTP compression;
The "Accept-encoding: gzip, deflate" parameter in the HTTP header of the request sent by the browser indicates that the gzip and deflate compression algorithms are supported.
2. If the browser supports HTTP compression, the web server checks the suffix of the request file;
To start static files and dynamic file suffixes, you must set them in metabase. xml.
Static files need to be set: hcfileextensions metabase property (click to jump to the msdn instructions)
Dynamic file needs to be set: hcscriptfileextensions metabase property (click to jump to the msdn instructions)
3. If the requested file is a static file such as HTML and CSS, and the file suffix is compressed, the web server will check whether the latest compressed file of the requested file already exists in the compression buffer directory;
4. If the compressed file of the request file does not exist, the web server returns the uncompressed request file to the browser and stores the compressed file of the request file in the compressed buffer directory;
5. If the latest compressed file of the request file already exists, the compressed file of the request file will be directly returned;
6. If the requested file is a dynamic file such as aspx and the file suffix is compressed, the web server dynamically compresses the content and returns it to the browser. The compressed content is not stored in the compressed cache directory.
5. enable HTTP compression in IIS
By default, IIS does not support HTTP compression and requires simple configuration.
1. Open the Internet Information Service (IIS) manager, right-click "website"-> "properties", and select "service ". In the "HTTP compression" box, select "compressing Application Files" and "compressing static files", and set "temporary directory" and "maximum temporary directory limit" as needed ";
2. Reminder: This step has no function on my machine and can be ignored.
In the Internet Information Service (IIS) manager, right-click "Web Service extension"-> "to add a new Web Service extension... ", enter the extension" httpcompression "in the" New web service extension "box, and add" required file "as C: windowssystem32inetsrvgzip. DLL, the Windows System directory may vary depending on your installation, select "set extension status to allow ";
3. Use a text editor to open C: windowssystem32inetsrvmetabase. XML (backup is recommended first ),
Locate location = "/lm/w3svc/filters/compression/gzip to set gzip compression,
Locate location = "/lm/w3svc/filters/compression/deflate" to set deflate compression.
The above two nodes are next to each other and the Set attributes are the same.
To Compress dynamic files, set hcdodynamiccompression to "true" and add the dynamic file suffix, such as aspx, to hcscriptfileextensions. If you need to compress static files, set hcdostaticcompression and hcdoondemandcompression to "true", and add the static file suffix to hcfileextensions, such as XML and CSS. hcdynamiccompressionlevel and hcondemandcomplevel indicate the compression ratio, the value ranges from 0 to 10. The default value is 0.
Hcdynamiccompressionlevel attribute description: hcdynamiccompressionlevel metabase Property
Hcondemandcomplevel attribute description: hcondemandcomplevel metabase Property
Note: These two attribute values are generally recommended to be set to 9, with the best cost performance. however, in my window Server 2003, the compression ratio is set no matter how, and the size of the files jquery and jquery UI (58 k/188 K) is the same after compression. (20 k/45 K ).
Here is my instance:
<Iiscompressionscheme location = "/lm/w3svc/filters/compression/deflate"
Hccompressiondll = "% WINDIR % system32inetsrvgzip. 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 % system32inetsrvgzip. 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, IIS may be using the file. Open "start"-> "Administrative Tools"-> "service", stop "IIS Admin Service", and save the settings;
5. Finally, restart IIS. You can go to the HTTP compression test site to verify the results. Taking jquery as an example, the original size of the core class library and UI class library is 57k and 188 K respectively, and the compressed size is 20 K and 45 K respectively:
We can use the content-encoding: gzip attribute in the HTTP header to determine that the returned data has enabled gzip compression:
Use yslow for detection. When only static File compression is started, Gzip compression is rated B:
When dynamic File compression is enabled at the same time, Gzip compression is rated as:
Vi. Summary
1. Stop the "IIS Admin Service" service when modifying the metabase. xml file. Otherwise, the service cannot be saved.
2. It is best to set static compression and dynamic compression ratio to 9.
3. In Step 2 above, the extension effect is the same even if no Web Service is added.
4. The compression ratio setting does not work for JS files, and the size is always the same after compression.
5. The size of the image file remains unchanged even if Gzip is enabled.
VII. Summary
This article summarizes how to enable gzip compression in IIS. in my project half a year ago, I enabled gzip for my website. Today, I want to organize my own knowledge so that I can review it when I forget it. in addition, Gzip compression is also enabled for CDN provided by chinacache.
The Firefox official website searches for the yslow plug-in, which relies on firebug.
Http://www.mozillaonline.com/