为什么我的 javascript 文件有时会被压缩,有时则不会?(IIS Gzip 问题)
我在 iis 设置中为 javascript 文件启用了 gzip,这是相应的配置部分。
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="10" dynamicCompressionLevel="8" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/soap+msbin1" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
目前,当我下载 js 文件时,服务器似乎有时返回 gzip 文件,有时则不返回。我不知道为什么,以及如何调试。
如果一个文件已经被 gzip 压缩,它应该缓存在本地磁盘中,下次有人再次访问该文件时,iis 内核应该直接返回缓存的 gzip 文件,而不需要再次压缩。是这样吗?
i enable gzip for javascript file in my iis settings, here 's the corresponding config section.
<httpCompression directory="%SystemDrive%\inetpub\temp\IIS Temporary Compressed Files">
<scheme name="gzip" dll="%Windir%\system32\inetsrv\gzip.dll" staticCompressionLevel="10" dynamicCompressionLevel="8" />
<dynamicTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/soap+msbin1" enabled="true" />
<add mimeType="*/*" enabled="false" />
</dynamicTypes>
<staticTypes>
<add mimeType="text/*" enabled="true" />
<add mimeType="message/*" enabled="true" />
<add mimeType="application/javascript" enabled="true" />
<add mimeType="application/x-javascript" enabled="true" />
<add mimeType="*/*" enabled="false" />
</staticTypes>
</httpCompression>
currently, when i download my js file, it seems that sometimes server return the gzip one, and sometimes not. i dont know why, and how to debug that.
If a file is already gzipped, it should be cached in local disk, and next time someone visit that file again, iis kernel should return the cache gzip file directly without compressing it again. Is that right?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
jaf,我自己弄清楚了,iis可能有一些错误。您可以设置frequenthitthreshold选项来强制脚本文件始终对文件进行gzip压缩。
我写了一篇关于这个错误的文章,但它是中文的,这是谷歌翻译的版本
为什么 gzip 在 IIS7 中不起作用?
jaf, i figure it out myself, there might be some bug in iis. you can set the frequenthitthreshold option to force the script file to always gzip the file.
i write a post about this bug, but it's in chinese, here 's the google translated version
Why gzip not work in IIS7?
该修复似乎确实是将 applicationHost.config 文件中的 system.webServer/serverRuntime 节点上的frequentHitThreshold 属性设置为 1。记录于 http://www.iis.net/ConfigReference/system.webServer/serverRuntime。
您可以通过以管理员身份执行以下命令来完成此操作:
警告 - “频繁点击”概念似乎并不特定于压缩。不知道这样设置会不会有其他后果!
The fix indeed seems to be setting the frequentHitThreshold attribute to 1 on the system.webServer/serverRuntime node in the applicationHost.config file. Documented at http://www.iis.net/ConfigReference/system.webServer/serverRuntime.
You can do this by executing the following command as an administrator:
A word of warning - the "frequent hit" concept does not seem specific to compression. I have no idea whether there are other consequences as a result of setting this!
清除浏览器缓存,然后重试。
Clear your browser cache, and try again.