问题描述
我有一个 Azure 网站/Web 应用程序,它提供静态 JS 和 CSS 文件的速度非常慢,但提供二进制文件似乎非常好.
I have an Azure Website/Web App that is incredibly slow to serve static JS and CSS files but seems perfectly fine serving binary.
为了测试这个问题,我上传了两个 30MB 的文件,一个 big.js 和另一个 big.rar.如果幸运的话,JS 文件的下载速度约为 100KB/s.RAR 文件的下载速度约为 4,000KB/s.结果非常一致.
To test the problem I uploaded two 30MB files, one big.js and the other big.rar. The JS file downloads at around 100KB/s if I'm lucky. The RAR file downloads at around 4,000KB/s. The results are extremely consistent.
我已经检查了 Fiddler 并且在这两种情况下都发生了 gzip 压缩.正如预期的那样,JS 文件以 MIME 类型 application/x-javascript 发送,而 RAR 文件以 application/octet-stream 发送.
I've checked in Fiddler and gzip compression is occurring in both cases. As expected, the JS file is being sent with the MIME type application/x-javascript whereas the RAR file is being served as application/octet-stream.
我很难理解这一点 - 为什么 IIS 提供一种类型的静态内容比另一种慢得多?
I am struggling to understand this - why would IIS serve one type of static content so much slower than another?
推荐答案
我们遇到了这个问题,并且能够在 Azure 支持团队的帮助下解决这个问题.问题是慢速文件会使用 TransferEncoding: Chuncked.他们建议我们强制静态压缩来解决这个问题.
We had this issue, and was able to resolve this with the help of Azure Support Team. The issue was that the slow files would use TransferEncoding: Chuncked. They suggested that we force static compression to get around this issue.
我们必须将以下内容添加到 :
We had to add the following to <system.webServer>
:
<serverRuntime enabled="true" frequentHitThreshold="1" frequentHitTimePeriod="00:00:20" />
这篇关于Azure 网站提供静态 JS/CSS 的速度很慢,但不是二进制的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!