我怎样才能减少我的javascripts的加载时间?(How can I reduce the load time of my javascripts?)

编程入门 行业动态 更新时间:2024-10-25 14:31:20
我怎样才能减少我的javascripts的加载时间?(How can I reduce the load time of my javascripts?)

我的页面上有以下代码:

<script src="/Scripts/common/layout/addAccessControls.js"></script> <script src="/Scripts/common/layout/addAjaxControls.js"></script> <script src="/Scripts/common/layout/addBodyControls.js"></script> <script src="/Scripts/common/layout/addContentControls.js"></script> <script src="/Scripts/common/layout/addThemeControls.js"></script> <script src="/Scripts/common/layout/hashClick.js"></script> <script src="/Scripts/common/layout/setSideBar.js"></script>

所有脚本会一个接一个地加载是否正确? 如果有的话,我可以同时做多个负载吗?

只是为了澄清这个问题。 我可以缩小这些和concat,也许他们已经被拼写和concate :-)我有什么需要找出是加载过程给这些确切的文件。 它是一个接一个的文件吗? browswer是否对并行加载做任何事情? 谢谢

I have the following code on my page:

<script src="/Scripts/common/layout/addAccessControls.js"></script> <script src="/Scripts/common/layout/addAjaxControls.js"></script> <script src="/Scripts/common/layout/addBodyControls.js"></script> <script src="/Scripts/common/layout/addContentControls.js"></script> <script src="/Scripts/common/layout/addThemeControls.js"></script> <script src="/Scripts/common/layout/hashClick.js"></script> <script src="/Scripts/common/layout/setSideBar.js"></script>

Is it correct that all the scripts will load one after another? If so is there a way I can make more than one load at once?

Just to clarify the question a bit. I can minify these and concat and maybe they're already mimified and concated :-) What I am intersted to find out is the load process given these exact files. Is it one file after the other. Does the browswer do anything to parallel load. Thanks

最满意答案

那么,第一个问题是脚本一个接一个地加载。 第二个问题是请求的数量。 请求越多,需要的时间越长。

最简单的方法是将服务器端的文件连接成一个.js文件,以便只剩下一个请求。 这会加速事情。

如果你另外缩小脚本,这也会加快速度。

根据您使用服务器端的框架,有关于如何执行此操作的各种解决方案。 例如,对于Node.js,您可以使用Piler在运行时执行此操作。

或者,当然,您可以始终通过构建作业分别手动执行此操作。

PS:当然,您可以使用其他机制来加载脚本文件,例如动态添加脚本标签,这将允许您并行加载。 有关详细信息,请参阅http://blogs.msdn.com/b/kristoffer/archive/2006/12/22/loading-javascript-files-in-parallel.aspx 。

Well, first problem is that the scripts are loaded one after the other. Second problem is the number of requests. The more requests, the longer it takes.

Most simple approach would be to concat the files server-side into one single .js file so that you only have one request left. This will speed up things.

If you additionally minify the scripts, this will speed up things, too.

Depending on what framework you use server-side there are various solutions on how to do this. E.g., for Node.js you can use Piler to do this at runtime.

Or, of course, you can always do this manually, respectively via a build job.

PS: And, of course, you can use other mechanisms to load scripts files, such as dynamically adding script tags which will allow you to parallelize loading. See http://blogs.msdn.com/b/kristoffer/archive/2006/12/22/loading-javascript-files-in-parallel.aspx for details.

更多推荐

本文发布于:2023-07-28 23:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1310133.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:加载   时间   javascripts   time   load

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!