我有一个站点,其中包含大量引用的 .js 文件;这些都是相当小的文件,但我想将我的方法按主题/功能分开。
是将所有方法保存在一个 .js 文件中更好,还是拥有许多(~ 20 - 30)个小文件都只包含一些行是否没有问题?
最佳答案
在开发时一定要将它们分开,但您应该考虑将它们捆绑到一个文件中以进行生产。
sitepoint.com 上有很好的讨论
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.
关于javascript - jQuery/JavaScript - 有很多小的 .js 文件时的性能问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/316944/