简体   繁体   中英

How to find out why Javascript is downloading so slowly?

I have an ASP.NET MVC project, which is running as slow as molasses. I opened up Fiddler on one particular call, and found several calls where there's a lot of room for improvement, to say the least:

在此处输入图片说明

The blue lines I understand are calls to my controller, and I understand where to go to optimize that stuff. But I see a bunch of green lines (which I assume means javascript), and those are also taking a heckuva long time. I must assume that jQuery and Kendo scripts don't normally take 4-6 seconds to turn around, so there must be something in our project code that's causing the slowness. But how do I track down what code needs optimization?

EDIT: @DaggNabbit in comments below points out that the slowness is because these Javascripts are being called with a cachebuster parameter, so they're being downloaded anew with every call! But I can't see anywhere in my code where we're explicitly adding a cachebuster. eg:

<script src="@Url.Content("~/Scripts/kendo.web.min.js")"></script>
...
@Scripts.Render("~/bundles/jquery", "~/bundles/jquerymobile")

I'm really not a UI expert, but I can't see where the cachebuster is coming from. Any other ideas?

为了提高性能,您可以使用javascript闭包和css闭包来负责将所有.js文件绑定到一个文件中,并将所有css文件绑定到另一个文件中,这样会增加加载时间。

The problem that @DaggNabbit correctly identified is that the javascripts were being called using a cachebuster parameter. I've invited him to post his answer as the correct answer; when he does so I'll give him answer credit.

Meanwhile, if you're interested in why the cachebuster was being inserted, see here .

I would suggest to bundle all the javascript into one compressed.js file and all css file into one compressed.css file. Which will reduced the time taken to load.

Currently, It takes a 4-6 seconds because js/css file wait for the other file to load completely and than make its own request to the server for his process. You need code optimization in your query when calling your controller on page load as well.

You will get free dll to compressed and bundle all js/css file into one compressed file.

Hope you get my point what i mean to say.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM