ArticleDirectory
- User Interface
- Command Line
- Configuration
- WMI
Enable HTTP compression for static content
You can run the following procedure: Use the user interface (UI), run the appcmd.exe command in the command line window, edit the configuration file directly, or write a WMI script.
UI
Open the IIS manager and navigate to the level you want to manage. For information about how to open IIS manager, see open IIS Manager (IIS 7 ). For information about how to navigate between different locations of the UI, see navigation in IIS Manager (IIS 7 ).
In"Function view", Double-click"Compression".
In"Compression"Page, select"Enable static content compression"The box next to it.
In"Operation"In the pane, click"Application".
Command Line
To enable HTTP compression for static content, enter the following command at the command prompt and press Enter:
Appcmd set config/section: urlcompression/dostaticcompression: True
For more information about appcmd.exe, see appcmd.exe (IIS 7 ).
Configuration
The process in this topic affects the following configuration elements:
<Urlcompression>
For more information about IIS 7 configuration, see IIS 7.0: IIS setting architecture on msdn (which may be an English page ).
WMI
Use the following WMI classes, methods, or attributes to execute this process:
- Httpcompressionsection. schemes. dostaticcompressionAttribute
- HttpcompressionschemeelementClass
For more information about WMI and IIS, see Windows Management Instrumentation (Wmi) in IIS 7 ). For more information about the classes, methods, or attributes associated with this process, see the iis wmi provider reference on the msdn website (which may be an English page ).
Source:
Http://technet.microsoft.com/zh-cn/library/cc754668%28WS.10%29.aspx
Note: by default, it will only work in the root directory of your website. If you want to use gzip In the JS and CSS folders, You need to perform the above operations in the corresponding directory of the site.
For more information, see
Http://tool.chinaz.com/Gzips/
Test, of course, you can be specific to CSS and JS such as (.com/js/js.js ).
Of course, this configuration may be invalid. The solution is as follows:
First open IIS management, select the site I want to set up, and then find the MIME types in the functional area on the right to see if there are. js options.
If yes, set the. js value to: Application/X-Javascript. Remember not to mention X-Some netizens will introduce application/JavaScript.
I tried it in win2008 + iis7, but it will not be compressed without adding X.
Of course, it is better to compress JavaScript before uploading it. You can find the tbcompressor tool on the Internet. This tool is compress well.
First open IIS management, select the site I want to set up, and then find the MIME types in the functional area on the right to see if there are. js options.
If yes, set the. js value to: Application/X-Javascript. Remember not to mention X-Some netizens will introduce application/JavaScript.
I tried it in win2008 + iis7, but it will not be compressed without adding X.
Of course, it is better to compress JavaScript before uploading it. You can find the tbcompressor tool on the Internet. This tool is compress well.
Solution to enable gzip without compressing JS files in iis7
Iis7 has enabled static File compression (gzip) but does not compress. After searching, it is found that it is a MIME type setting problem in ii7.
Set the. js MIME type to application/JavaScript
Check the page again. Gzip is enabled.
However, a few days later, I found that some JS files were compressed, but some did not.
The reason is that the type is not set when the JS file is referenced.
<SCRIPT> </SCRIPT>
<SCRIPT src = "A. js"> </SCRIPT>
AddType = "text/JavaScript"Type.
Occasionally invalid (will be valid for a while) Solution
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 set the same attributes.
To Compress dynamic files, set hcdodynamiccompression to "true",
Add the dynamic file suffix you want to compress in hcscriptfileextensions, such as aspx;
To Compress static files, set hcdostaticcompression and hcdoondemandcompression to "true",
Add the extension name of the static file to be compressed in hcfileextensions, such as XML and CSS;
Hcdynamiccompressionlevel and hcondemandcomplevel indicate the required 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 effectiveness.
<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>
Note:
1. Stop IIs before editing metabase. xml. You can use net stop IISADMIN
2. After the modification is complete, enable the IISADMIN service and execute the iisreset command.
Seo Testing
Whether compression has an impact on Seo. After testing, it can still be well recorded after being enabled.
For more information about the SEO impact, see the following articles.
Specific efficiency issues will be monitored for further research.
If the preceding settings are invalid, orMetabase. XML does not have a response node. Use the following methods to solve this problem:
FirstAdd the following content to Web. config, set frequenthitthreshold to 1, and set frequenthittimeperiod to 10 minutes.
<System. webserver>
<Serverruntime enabled = "true"
Frequenthitthreshold = "1"
Frequenthittimeperiod = "00:10:00"/>
</System. webserver>
SecondOpen % WINDIR % \ system32 \ inetsrv \ appcmd.exe, enter the following command string on the command line interface, and press ENTER
Set config-Section: system. webserver/serverruntime-frequenthitthreshold: 1
IfThe execution in the appcmd.exe window cannot stay. You can execute consecutive commands:
% Windir % \ system32 \ inetsrv \ appcmd.exe set config-Section: system. webserver/serverruntime-frequenthitthreshold: 1
% Windir % \ system32 \ inetsrv \ appcmd.exe set config-Section: system. webserver/serverruntime-frequenthittimeperiod: 00:10:00