IIS7 Enable gzip

Source: Internet
Author: User

Compress what

The server chooses what to compress based on the file type, but this is usually limited to its configuration. Many websites compress their HTML documents. Compressing scripts and style sheets is also worthwhile, with compressed content including XML and JSON for any text response, but only for scripts and stylesheets, but pictures and PDFs should not be compressed because they are already compressed, and trying to compress them will only waste CPU resources. It is also possible to increase the file size.

Compression cost: Server CPU resources, client decompression overhead

Enable method:

Turn on IIS---features are----compress---enable dynamic content compression, enable static content compression

Open the ApplicationHost.config file for C:\Windows\System32\inetsrv\config under Path

Found it

<scheme name= "gzip" dll= "%windir%\system32\inetsrv\gzip.dll"/>
<dynamicTypes>
<add mimetype= "text/*" enabled= "true"/>
<add mimetype= "message/*" enabled= "true"/>
<add mimetype= "Application/x-javascript" enabled= "true"/>
<add mimetype= "Application/javascript" enabled= "true"/>
<add mimetype= "*/*" enabled= "false"/>
</dynamicTypes>
<staticTypes>
<add mimetype= "text/*" enabled= "true"/>
<add mimetype= "message/*" enabled= "true"/>
<add mimetype= "Application/javascript" enabled= "true"/>
<add mimetype= "Application/atom+xml" enabled= "true"/>
<add mimetype= "Application/xaml+xml" enabled= "true"/>
<add mimetype= "*/*" enabled= "false"/>
</staticTypes>

As we can see, IIS is actually depending on the MIME type to decide whether to enable HTTP compression (the various HTML component MIME types), as well as options such as compression ratios. As you can see, the picture is not compressed by default, because the compression ratio of the picture is too low.

We note that for JavaScript, the above different MIME types are configured with different compression methods. JavaScript has three common MIME types, text/javascript,application/x-javascript,application/javascript. These three types are legal, and there is no difference in modern browsers. However, because the MIME type of JS file in IIS7 is set to Application/x-javascript by default, that is, for JS file, dynamic content compression is used instead of static content compression, so the JS file is sometimes compressed and sometimes not compressed.

Since the JS file is usually stable and will no longer be modified, it is recommended to change to static compression-that is, the Application/x-javascript in the Dynamictypes section is moved to the static compression section. This ensures that each script is compressed and returned.

    • The difference between static compression and dynamic compression

HTTP compression in IIS7 is divided into "static content compression" and "Dynamic content compression", in fact, the first contact of these two names is very confusing. What is dynamic content and what is static content? In fact, accurate translation should be "static compression" and "dynamic Compression". These two words reflect the compression behavior of IIS. For MIME types that are configured in the Statictypes section, static compression is enabled, that is, when the file is first requested, IIS compresses it and puts it in a temporary folder. The next time someone requests this file, remove the compressed version directly from the Temp folder without having to re-perform the compression process. HTTP requests that are configured in the MIME type in the Dynamictypes section will have dynamic compression enabled, that is, each request, the host will compress the requested content-either a static file stored in the file system or the content returned by the ISAPI-without caching it. This compression ratio due to different host performance will be adjusted, so we request the JS file when the JS file can be found sometimes compression sometimes not compressed. It is important to note that for requests that go through ISAPI, you cannot use the static compression method

IIS7 Enable gzip

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.