Rails 链轮资产。什么时候需要

Rails Sprockets assets. When is it necessary

我想知道 Sprockets 在 Rails 上的最佳用例是什么。
据我了解,当您拥有将用于所有或几乎所有视图的 javascript 和 css 资源时,最好 使用它。喜欢 jquery.
但作为示例,如果我有一个用户控制器,我将有一个 users.js 或 users.coffee 文件。由于以下原因,它包含在 application.js 文件中:
//= require_tree .

但是如果对于我的 users.js 我包含
//= require chartkick
它将在 application.js 中包含 chartkick 依赖项,从而增加文件大小。
在这种情况下,我是否应该将 users.js 与链轮 application.js 文件分开?

Sprockets 只是一个通用的资产管道。引用Max

Sprockets is a general assets pipeline. There is nothing that says that you have to concatenate everything into a single file just because you are using Sprockets. Rather what sprockets provides is concatenation, minification and source maps. Its not just a question of file size. You also have consider caching after the first page, and limits to the amount of assets a browser can load concurrently. If you want a best practice then its to not require the same thing twice. Either put the dependency it in your manifest or the subfiles - not both.