Why does iis enable GZIP to compress Css javascript files?

Source: Internet
Author: User

Yesterday, a friend asked me why iis gzip is invalid. Later, I found a solution through repeated searches. If you have any questions, please refer to it.

After IIS enables GZIP compression, it thought it could compress all files, including html, CSS, JS, and images. But when I checked, I found that this was not the case, only html files are compressed, while CSS and JS files are not compressed.

The detection results in the website speed diagnosis of the card network:

The html webpage has enabled GZip compression successfully.

GZip compression is not enabled for css files

Later studies found that when IIS enables GZip, only html webpages are compressed by default. If you need to compress files such as css and js, you also need to simply configure a file.

Open the C: WINDOWSsystem32inetsrvMetaBase. xml file, and search for "IIsCompressionScheme". You will find three sections. You can set only the first two. "/LM/W3SVC/Filters/Compression/gzip" is used to set gzip Compression, and "/LM/W3SVC/Filters/Compression/deflate" is used to set deflate Compression.

To Compress static files, set HcDoStaticCompression and HcDoOnDemandCompression to "TRUE", and add the static files to be compressed in the attributes of HcFileExtensions, such as css and js;

To Compress dynamic files, set HcDoDynamicCompression to "TRUE", and add the dynamic files to be compressed in the HcScriptFileExtensions attribute, such as aspx and php.

In addition, the HcDynamicCompressionLevel attribute and HcOnDemandCompLevel attribute are generally recommended to be set to 9, with the best cost effectiveness.

Refer to the following parameter settings:

The Code is as follows: Copy code

<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
Css
Js
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
Css
Js
Xml"
HcOnDemandCompLevel = "9"
HcPriority = "1"
HcScriptFileExtensions = "asp
Aspx
Dll
Exe"
>
</IIsCompressionScheme>

After the settings are complete, restart IIS and check that the css, js, and other files have been enabled successfully.

Related Article

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.