我试图支持我的静态文件在IIS下的GZip压缩(这应该是默认启用,但不是),但目前为止没有工作。 以下是web应用程序的web.config文件中的<system.webServer>
节点下的部分;
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="9" /> <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="application/json" enabled="true" /> <add mimeType="*/*" enabled="false" /> </dynamicTypes> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="application/atom+xml" enabled="true" /> <add mimeType="application/xaml+xml" enabled="true" /> <add mimeType="*/*" enabled="false" /> </staticTypes> </httpCompression> <urlCompression doStaticCompression="true" />
我用Google Chrome试了一下。 这里是请求标题;
接受:text / html,application / xhtml + xml,application / xml; q = 0.9, / ; q = 0.8
接收字符集:ISO-8859-1,utf-8; Q = 0.7,*; Q = 0.3
- 在Win 7中从networking共享运行.NET应用程序?
- 无法在Windows Server 2003 DC上安装Active Directorypipe理网关服务,因为缺less修补程序969166
- 是否有IIS和.net应用程序的最佳实践指南?
- 将机器密钥添加到负载平衡环境中的machine.config以多个版本的.net框架
- ASP.NET MVC共享虚拟主机推荐? (或者,好的Windows VPS提供商?)
接受编码:gzip,放气,SDCH
接受语言:EN-US,EN; Q = 0.8
caching控制:无caching
连接:保持活跃
主持人:我-网站url
附注:无caching
User-Agent:Mozilla / 5.0(Windows NT 6.0)AppleWebKit / 534.30(KHTML,如Gecko)Chrome / 12.0.742.122 Safari / 534.30
这些是响应头;
接受-范围:字节
内容长度:232651
内容types:应用程序/ x-的JavaScript
date:2011年8月4日星期四08:58:19 GMT
ETag的: “a69135734a50cc1:0”
Last-Modified:星期一,01八月2011 12:56:37 GMT
服务器:Microsoft-IIS / 7.5
X-已启动方式:ASP.NET
我检查applicationHost.config文件,发现像下面的一些节点;
---- <section name="httpCompression" allowDefinition="AppHostOnly" overrideModeDefault="Deny" /> ---- <section name="urlCompression" overrideModeDefault="Allow" /> ---- <httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files"> <scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" /> <staticTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add mimeType="application/x-javascript" enabled="true" /> <add mimeType="application/atom+xml" enabled="true" /> <add mimeType="application/xaml+xml" enabled="true" /> <add mimeType="*/*" enabled="false" /> </staticTypes> </httpCompression> ---- <urlCompression />
我在这里错过了什么?
看起来您可能没有在temp压缩文件夹上正确设置权限。 您需要确保用户的IIS安装(或应用程序)在对压缩文件夹具有写入权限的情况下运行。
更多在这里
经过大量的search,我终于find了在我的IIS 7.5上压缩的工作。 首先,IIS不会压缩文件,除非它经常加载。 这引出了一个问题:“IIS经常考虑什么?” 那么,默认是每10秒2次。 哎呀!
可以在web.config中更改此设置,但是需要先在applicationHost.config中解锁该部分。 这里是命令:
首先解锁部分:
C:\ Windows \ System32 \ inetsrv \ appcmd.exe unlock config /section:system.webServer/serverRuntime
在configurationpath“MACHINE / WEBROOT / APPHOST”中解锁“system.webServer / serverRuntime”部分。
现在完成了,编辑web.config文件并添加serverRuntime元素:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <system.webServer> <serverRuntime frequentHitThreshold="1" frequentHitTimePeriod="10:00:00" /> ...
在这种情况下,我将它设置为在10小时内打一次文件。 您可以根据需要调整这些值。 以下是解释serverRuntime元素的文档:
http://www.iis.net/configreference/system.webserver/serverruntime
我希望这可以帮助你的压缩工作。
注意:你也可以在applicationHost.config文件中设置serverRuntime元素,但是我select在web.config中更改它,因为我们有许多服务器和不同站点的服务器场,而且我更容易控制它从这个粒度级别。
这对我有用:
<urlCompression doStaticCompression="true" doDynamicCompression="true" dynamicCompressionBeforeCache="true" /> <httpCompression noCompressionForRange="false" noCompressionForHttp10="false" noCompressionForProxies="false"> <dynamicTypes> <add mimeType="text/css" enabled="true" /> </dynamicTypes> <staticTypes> <add mimeType="text/css" enabled="true" /> </staticTypes> <staticTypes> <add mimeType="text/javascript" enabled="true" /> </staticTypes> </httpCompression>
还有文本/ JavaScript的MIMEtypes,你只有应用程序之一。 这是一个问题,直到我包括文字/ …