我在 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 文件而不用再次压缩它。是吗?
最佳答案
jaf,我自己弄明白了,iis 可能有一些错误。您可以设置 frequenthitthreshold 选项以强制脚本文件始终对文件进行 gzip 压缩。 我写了一篇关于这个错误的帖子,但它是中文的,这是谷歌翻译的版本 Why gzip not work in IIS7?
关于javascript - 为什么我的 javascript 文件有时压缩有时不压缩?(IIS Gzip 问题),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2779118/