简体   繁体   English

如何找出为什么Javascript下载如此缓慢?

[英]How to find out why Javascript is downloading so slowly?

I have an ASP.NET MVC project, which is running as slow as molasses. 我有一个ASP.NET MVC项目,它的运行速度与糖蜜一样慢。 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: 我在一个特定的呼叫中打开了Fiddler,并发现了至少可以说有很多改进空间的几个呼叫:

在此处输入图片说明

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. 但是我看到了一堆绿线(我认为这是指javascript),并且这些绿线也花费了很长时间。 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. 我必须假设jQuery和Kendo脚本通常不需要4到6秒钟的时间就可以翻转,因此我们的项目代码中一定有某些东西会导致速度变慢。 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! 编辑: @DaggNabbit在下面的注释中指出,缓慢是因为这些Javascript是使用cachebuster参数调用的,因此每次调用都将重新下载它们! 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. 我确实不是UI专家,但是我看不到cachebuster的来源。 Any other ideas? 还有其他想法吗?

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

The problem that @DaggNabbit correctly identified is that the javascripts were being called using a cachebuster parameter. @DaggNabbit正确识别的问题是正在使用cachebuster参数调用javascript。 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 . 同时,如果您对为何插入cachebuster感兴趣,请参见此处

I would suggest to bundle all the javascript into one compressed.js file and all css file into one compressed.css file. 我建议将所有的javascript捆绑到一个Compressed.js文件中,并将所有的CSS文件捆绑到一个Compressed.css文件中。 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. 当前,这需要4到6秒钟,因为js / css文件等待另一个文件完全加载,然后向服务器发出自己的请求以进行处理。 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. 您将获得免费的dll进行压缩并将所有js / css文件捆绑为一个压缩文件。

Hope you get my point what i mean to say. 希望你明白我的意思。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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