问题
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. e.g.:
<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?
回答1:
For increase the performance you can use javascript closure and css closure these are responsable for binding all the .js files into one file and all the css files into antoher single file so that will increase your loading time.
回答2:
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.
回答3:
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.
来源:https://stackoverflow.com/questions/16395026/how-to-find-out-why-javascript-is-downloading-so-slowly