我正在试用 require.js 并且只包含在我主页的 js 文件中。 main.js 加载加载其他脚本。
我正在使用 yslow 测试我网站的性能。它说我的页面有 15 个 js 文件,我应该尝试将它们合并为一个。这不就是require.js的目的吗?我不应该将我所有的 js 合并到一个大文件中吗?
最佳答案
嗯,RequireJS 的想法是将您的脚本构建成模块(小部分)。这样做时,您会注意到您将要处理许多模块,因此也会处理许多文件。
要解决“很多文件”的问题,RequireJS has an optimizer .
RequireJS has an optimization tool that does the following
- Combines related scripts together into build layers and minifies them via UglifyJS (the default) or Closure Compiler (an option when using Java).
- Optimizes CSS by inlining CSS files referenced by @import and removing comments.
关于javascript - 页面加载时有很多请求(require.js),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11169229/