次の方法で共有


How do I enable GZip compression for my web server in IIS?

GZip/Deflate compression will compress the response payload from the IIS web server to the browser.  Pages that seem to run fast on the server but run slow over the network will see a big speed increase.  I typically see around a 60% to 70% reduction in network traffic with GZip enabled.  This could mean transfer rates to the browser up to 4x faster!   Best of all, GZip/Deflate compression is built-in IIS out-of-the-box!

 

Who uses GZip compression for their web site:
- Microsoft.com
- Google.com
- Yahoo.com
- CNN.com
- eBay.com
- Facebook.com
- well, just about everyone.

 

Command-line example of typical usage settings to enable GZip compression for both dynamic and static content (from within Inetpub\AdminScripts and running IIS 6.0):

cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoDynamicCompression true
cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoStaticCompression true
cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcDynamicCompressionLevel 7
cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcOnDemandCompLevel 7
cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcFileExtensions "txt" "htm" "html" "js" "htc"
cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcDynamicCompressionLevel 7
cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcFileExtensions "txt" "htm" "html" "js" "htc"
cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcOnDemandCompLevel 7
cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForHttp10 true
cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForProxies true
IISReset

 

Command Line 

 

Setting Definitions for IIS 6.0

 

  • Enable compression for application files with dynamic content i.e. ASP, ASPX (default is false):
    cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcDoDynamicCompression true

  • Enable compression for static files i.e. HTM, JS, CSS (default is false):
    cscript adsutil.vbs set w3svc/filters/compression/parameters/HcDoStaticCompression true

  • The following lines will leave the default and add support for ASP.NET .ASPX file extension which is dynamic content (default file extionsions for dynamic content are .ASP, .DLL, .EXE):
    cscript adsutil.vbs set W3Svc/Filters/Compression/Gzip/HcScriptFileExtensions "asp" "dll" "exe" "aspx"
    cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcScriptFileExtensions "asp" "dll" "exe" "aspx"

  • The following lines will leave the default and add support for JavaScript file extension which is static content (default file extionsions for static content are .TXT, .HTM, .HTML):
    cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcFileExtensions "txt" "htm" "html" "js"
    cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcFileExtensions "txt" "htm" "html" "js"

  • The following will set the compression level which is a range from 0 to 10 for dynamic content (default is 0 which requires the lowest amount of CPU - i prefer level 7)
    cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcDynamicCompressionLevel 7
    cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcDynamicCompressionLevel 7

  • The following will set the compression level which is a range from 0 to 10 for static content (default is 10 - i prefer level 7)
    cscript adsutil.vbs set W3Svc/Filters/Compression/GZip/HcOnDemandCompLevel 7
    cscript adsutil.vbs set W3Svc/Filters/Compression/Deflate/HcOnDemandCompLevel 7

  • If you are concerned with older proxy servers that claim to support the HTTP 1.0 specification but may not support compression you may want to use the following to only support HTTP 1.1 specification - only needed if having issues (default is false):
    cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForHttp10 true

  • If you want to completely disable compression for requests that come through proxy servers - only needed if having issues (default is false):
    cscript adsutil.vbs set W3Svc/Filters/Compression/Parameters/HcNoCompressionForProxies true

 

NOTE: After making these Metabase changes, you will need to restart IIS.  Also, if you are using load balancers for your web servers, it may be preferable to offload GZip compression to them.

 

For more information on Using HTTP compression:
https://technet.microsoft.com/en-us/library/cc778828.aspx

For more information on enabling/disabling HTTP compression on an individual web site or web site folder basis:
https://technet.microsoft.com/en-us/library/cc782942.aspx

For more information on Using HTTP compression for Faster Downloads:
https://technet.microsoft.com/en-us/library/cc756725.aspx

For more information on Changes to Compression in IIS7
https://blogs.iis.net/ksingla/archive/2006/06/13/changes-to-compression-in-iis7.aspx

Comments