IIS7 compressing JS files and enabling gzip compression

Source: Internet
Author: User

Compressing JS files

To open the configuration file for IIS 7: C:\Windows\System32\inetsrv\config\applicationHost.config

Added in <staticcontent lockattributes= "Isdocfooterfilename" >:

<remove fileextension= ". js"/>
<mimemap fileextension= ". js" mimetype= "Text/javascript"/>

Related article: Getting IIS 7 to Compress JavaScript

Above transfer from: http://group.cnblogs.com/topic/31935.html

Turn on Configure HTTP compression (GZIP)

Configuring gzip compression in IIS7 is a lot easier than IIS6, and gzip compression is enabled by default. If not, you can find the "compress" item in the function view, then you will see the "Static content compression" and "Dynamic content Compression" two options, check it.

Configuring file types with compression enabled and other options

When gzip compression is turned on, IIS does not have compression enabled for all content, but is selectively compressed. Unfortunately, we cannot configure these compression options directly in the IIS7 manager. We first need to find the ApplicationHost.config file under the C:\Windows\System32\inetsrv\config folder, open and then find the following section:

"%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">     <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="*/*" enabled="false" />     </dynamicTypes>     <staticTypes>         <add mimeType="text/*" enabled="true" />         <add mimeType="message/*" enabled="true" />         <add mimeType="application/javascript" enabled="true" />         <add mimeType="*/*" enabled="false" />     </staticTypes>

As we can see, IIS is actually depending on the MIME type to determine whether HTTP compression is enabled, and 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 the JS file in IIS7 is set to Application/x-javascript by default, that is, for JS files, dynamic content compression is used instead of static content compression, which can cause JS files to be compressed sometimes. Sometimes it's 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 obvious that static compression consumes a certain amount of storage space, but is fast, while dynamic compression does not occupy storage space, but consumes CPU time, and the compression ratio is not constant. For requests that pass through an ISAPI, you cannot use static compression. For example, the content returned by WCF.

See this article for more detailed information: Using HTTP Compression for Faster Downloads.

--Kevin Yang

Above transfer from: http://www.imkevinyang.com/2009/06/iis7%E9%85%8D%E7%BD%AEgzip%E5%8E%8B%E7%BC%A9.html

From:http://www.cnblogs.com/xuejianxiyang/p/5517542.html

IIS7 compressing JS files and enabling gzip compression

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.