This article introduces how to enable Gzip compression in IIS in text format. If you need it, please refer to this article.I. Summary
This article summarizes how to enable Gzip compression in IIS to reduce the transfer size of web pages over the network, so as to increase the page display speed before users.
Ii. Preface
Gzip is critical when the website is enabled. 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
The Web server processes HTTP compression 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)
Set the dynamic file: HcScriptFileExtensions Metabase Property (click to jump to the MSDN description) 3. if the requested file is a static file such as HTML and CSS and the file suffix is compressed, the Web server checks whether the latest compressed file of the requested file already exists in the compressed 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 is 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. simple configuration is required. 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 effect and can be ignored.
Nternet Information Service (IIS) manager, right-click "Web Service extension"-> "to add a new Web Service extension... ", enter the extension" HTTP Compression "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 --- For details, see MSDN
NDemandCompLevel attribute description: HcOnDemandCompLevel Metabase Property --- For details, see MSDN
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. Restart IIS. You can go to the HTTP compression test site to verify the result: YSlow detection. When only static File compression is started, Gzip compression is rated B. When dynamic File compression is started, Gzip compression is rated:
Vi. Summary
1. modify MetaBase. to stop the "IIS Admin Service" Service. otherwise, it 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.