35

I have an Azure Website/Web App that is incredibly slow to serve static JS and CSS files but seems perfectly fine serving binary.

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.

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.

I am struggling to understand this - why would IIS serve one type of static content so much slower than another?

Matt Jenkins
  • 2,507
  • 1
  • 24
  • 32
  • 1
    its downloading a 900KB js file in three minutes in my case – Yehia A.Salam May 02 '15 at 19:32
  • Did you ever find a solution to this? I'm actually getting 10 KB/s for text files unless I specify Ranges in the requests – makhdumi Aug 28 '15 at 19:48
  • you are not alone.... http://stackoverflow.com/questions/33134991/long-waiting-ttfb-time-for-scripts-styles-on-azure-website – ymz Jan 19 '16 at 23:51
  • Do you have some extension that would process text files such as Bundle that will compress/minify js files etc? – Akash Kava Jan 20 '16 at 08:45

3 Answers3

39

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" />
John Tseng
  • 5,957
  • 2
  • 23
  • 33
5

To elaborate on John Tseng's answer: (from here)

As you saw earlier, IIS 7 caches the compressed versions of static files. So, if a request arrives for a static file whose compressed version is already in the cache, it doesn’t need to be compressed again.

But what if there is no compressed version in the cache? Will IIS 7 then compress the file right away and put it in the cache? The answer is yes, but only if the file is being requested frequently. By not compressing files that are only requested infrequently, IIS 7 saves CPU usage and cache space.

By default, a file is considered to be requested frequently if it is requested two or more times per 10 seconds.

So, the reason your users are being served an uncompressed version of the javascript file is because it didn't meet the default threshold for being compressed; in other words, the javascript file was not requested 2 times within 10 seconds.

To control this, there is one attribute we must change on the <serverRuntime> element, which controls compression: frequentHitThreshold. In order for your file to be compressed when it is requested once, change your <serverRuntime> element to look like this:

<serverRuntime enabled="true" frequentHitThreshold="1" />

This will slightly impact your CPU performance if you have many javascript files that are being served and you have users quite often, but likely if you have users often enough to impact CPU from compressing these files, then they are already compressed and cached!

CC Inc
  • 5,569
  • 3
  • 29
  • 61
0

Looks like it was an issue on IIS 8.5 and not only Azure specific.

Now App service upgrade to Windows Server 2016 looks complete and this workaround should not be needed.