Enable gzip compression (IIS) to speed up client Website access

Source: Internet
Author: User
Tags metabase
How to enable gzip compression (HTTP compression) on IIS 1. 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" HTTP compression "in the" New web service extension "box, and add" required file "to c: \ windows \ system32 \ inetsrv \ gzip. DLL, the Windows System directory may vary depending on your installation, select "set extension status to allow ";

3. Open c: \ windows \ system32 \ inetsrv \ metabase. XML in a text editor (backup is recommended ),
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%\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, 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:

In the HTTP header:Content-encoding: GzipGzip compression is enabled for the data returned by attribute judgment:

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 six months ago, I enabled gzip for my website. Today, I want to organize my knowledge so that I can review it later.

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.