I. 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.
Two. 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.
three. 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 "Web Service Extensions"-> "Add a new Web service extension ...", in the new Web service Extension box, enter the extension "HTTP Compression" and add "required files" as C:\ Windows\system32\inetsrv\gzip.dll, where the Windows system directory may vary depending on your installation, 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.
four. Key summary
1. To stop the IIS Admin service when you modify the MetaBase.xml file. You cannot save it.
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.
five. Summary
This article summarizes how to enable gzip compression in IIS. I enabled gzip for the site in a six-year project, Today, finishing this article is mainly to organize their own knowledge in order to forget later review. In addition, the CDN provided by the ChinaCache company also has gzip compression enabled.