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.