jQuery / JavaScript - 有很多小.js文件的性能问题? [英] jQuery/JavaScript - performance-issue when having a lot of small .js-Files?

查看:113
本文介绍了jQuery / JavaScript - 有很多小.js文件的性能问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含大量引用的.js文件的网站;那些是相当小的文件,但我想让我的方法按主题/功能分开。

i've got a site with a lot of referenced .js-Files; those are rather small files, but I want to keep my methods separated by topic/functionality.

将所有方法保存在一个.js-File中是不是更好有很多(~20 - 30)小文件都只包含一些行没问题吗?

Is it better to keep all the methods in one .js-File or is it no problem to have many (~ 20 - 30) small files all including only some lines?

推荐答案

一定要保留它们单独进行开发,但你应该考虑将它们捆绑在一起用于生产。

By all means keep them separate for development, but you should consider bundling them together into one file for production.

sitepoint.com


对于这些文件中的每一个,HTTP
请求被发送到服务器,
然后浏览器在请求之前等待响应
下一个文件。
浏览器的限制(或限制)
通常会阻止并行下载。
这意味着对于每个文件,你
等待请求到达
服务器,处理
请求的服务器和回复(包括
)文件内容本身)与您联系。将
结束,其中一些可以使页面加载时间产生
的巨大差异。

For each of these files, an HTTP request is sent to the server, and then the browser awaits a response before requesting the next file. Limits (or limitations) of the browser generally prevent parallel downloads. This means that for each file, you wait for the request to reach the server, the server to process the request, and the reply (including the file content itself) to reach you. Put end to end, a few of these can make a big difference to page load times.

这篇关于jQuery / JavaScript - 有很多小.js文件的性能问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆