如何配置 IIS 以自动为支持它的客户端提供压缩的静态资源(图片、javascript、css 等) - 并为不支持压缩的客户端提供“正常”内容?
另外,IIS6 能否为我缓存资源的压缩版本,以便我不需要在每次请求时都消耗 CPU 周期来进行压缩?
我需要为网站上的特定文件夹启用此功能。
答案1
它可能不是 gzip,但这是有关 IIS 6 中的 HTTP 压缩的详细信息:http://www.microsoft.com/technet/prodtechnol/WindowsServer2003/Library/IIS/d52ff289-94d3-4085-bc4e-24eb4f312e0e.mspx?mfr=true
答案2
以下是设置所有内容的命令行选项:
ADSUtil.vbs Set W3SVC/Filters/Compression/Parameters/HcDoStaticCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/Parameters/HcDoOnDemandCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/Parameters/HcDoDynamicCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcDoStaticCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcDoOnDemandCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcDoDynamicCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcFileExtensions "asx" "css" "doc" "htm" "html" "js" "txt" "xml"
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcScriptFileExtensions "asp" "ashx" "asmx" "aspx" "axd" "dll" "exe" "svc"
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcOnDemandCompLevel 10
ADSUtil.vbs Set W3SVC/Filters/Compression/deflate/HcDynamicCompressionLevel 9
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcDoStaticCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcDoOnDemandCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcDoDynamicCompression TRUE
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcFileExtensions "asx" "css" "doc" "htm" "html" "js" "txt" "xml"
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcScriptFileExtensions "asp" "ashx" "asmx" "aspx" "axd" "dll" "exe" "svc"
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcOnDemandCompLevel 10
ADSUtil.vbs Set W3SVC/Filters/Compression/gzip/HcDynamicCompressionLevel 9
重置 IIS,清除缓存,打开 Fiddler,打开 IE,发出请求,然后,压缩内容就完成了!需要注意的是,动态级别压缩会随每个请求一起发生。博客圈表示,动态压缩级别 9 和 10 之间的权衡是,您需要考虑 9,因为与收益相比,它占用的 CPU 少得多。
这是我发现的在 IIS 6 上进行压缩的最简洁的方法,以上内容取自 Colin Bowern 在http://www.codinghorror.com/blog/2004/08/http-compression-and-iis-6-0.html