次の方法で共有


Page Loads slow and you notice certain files (js, html) seem to be extra slow downloading

Symptom

You notice particular files (.js, .html and more) are downloading very slowly

Cause

Certain files are sent back to the client as chunked encoded.  CDNs and Web Servers both show this behavior.  Chunked downloads are very expensive in terms of speed because each chunk is in essence treated like a separate download.  Chunked encoding is based on file type and file size.

OK, so WHY would Web Servers and CDNs do this?

This is so that modern browsers can start rendering content before the entire file arrives at the client. This includes html and js files. Typically most websites keep individual resources under 25K and that is why for most applications the delay is negligible. If your file is big (by web standards > 25 K) the delay you see is probably due to chunked encoding.  Also, some clients will not cache a file over 25K (another reason to keep the download small) such as some smaller devices like phones.

Resolution

Make the files smaller is the best resolution.  For example: Minify or break up large .js files.  There are a TON of suggestions for increasing the speed of your web page.  You can use Bing or Google to find them.  Basically, put script at the bottom of your page and use individual smaller downloads.  Visit a ‘good performing’ page and use the F12 tools of your browser or Fiddler from Telerik to see what is coming down, how big it is and if it is coming down in parallel. 

If you are simply looking to download these files faster as is (lets say you have an API that is downloading JS files) and you are using IIS or Azure App Services (aka Azure Web Apps) you can workaround this chunked encoded behavior by adding to your web.config in the <system.webServer> section:
<serverRuntime enabled="true" frequentHitThreshold="1" frequentHitTimePeriod="00:00:20" />

Conclusion

Web page performance tools are available to help you speed up your pages.  This particular post explains why some large files take a long time to download due to chunked encoding.  I hope you find this a useful explanation of why these files take longer to download and what to do to speed things up!

Comments

  • Anonymous
    April 17, 2017
    Hai Jeff Sanders, Adding section: worked like a charm for me. As said in this guide https://www.geekdashboard.com/factors-affecting-loading-speed-of-website/ I tried to reduce the no.of HTTP requests by merging all .js files into single file. Do you this it is recommended because that single .js file will be large in size or else should I make them as two files keeping important .js files in one file and next priority files in another file?
    • Anonymous
      April 19, 2017
      @Mithul, Modern browsers can download in parallel. Minimize the combined .js file. If it is > 25K I would break it up into a smaller parts.
      • Anonymous
        May 04, 2017
        @Jeff Sanders Thanks Jeff Sanders, my .js file is less than 20 KB and seems it is not required to break into multiple files.