简体   繁体   English

当有数百个资产文件时,Rails资产管道工作流程

[英]Rails asset pipeline workflow when there are hundreds of asset files

We recently converted a Rails 3.2 project to use the asset pipeline. 我们最近转换了一个Rails 3.2项目来使用资产管道。 Our app uses many asset files (~250 *.js.coffee files, another 200 or so *.jst.hamljs templates, and ~100 *.css.sass stylesheets). 我们的应用程序使用许多资产文件(~250 * .js.coffee文件,另外200个* .jst.hamljs模板和~100 * .css.sass样式表)。 As you'd expect, these are packaged into a much smaller number of asset files in production. 正如您所期望的那样,这些产品在生产中被打包成少量的资产文件。

In development and test environments, we deal with frequent timeouts and slow page-loads while recompiling and requesting individual assets. 在开发和测试环境中,我们处理频繁的超时和缓慢的页面加载,同时重新编译和请求单个资产。 Is there a better workflow that still allows automatic recompilation? 是否有更好的工作流程仍然允许自动重新编译?

We're running with default environment settings, except have set debug to false in development: 我们使用默认环境设置运行,除了在开发中将debug设置为false

config.assets.debug = false

This saves us hundreds of requests when reloading the page in development, but initial compilation still causes timeouts. 在开发中重新加载页面时,这可以节省数百个请求,但初始编译仍会导致超时。 There must be a better way, right? 必须有更好的方法,对吧?

Some options: 一些选择:

  • Limit what is required to be recompiled when requested via use of require_asset . 通过使用require_asset限制请求时重新编译的内容。 See this question and Sprockets #90 . 看到这个问题和Sprockets #90

  • Precompile assets: 预编译资产:

     $ RAILS_ENV=development bundle exec rake assets:precompile 
  • Increase timeouts. 增加超时。 This depends on how you have things setup and can be painful and problematic, eg Heroku is not a big fan of long requests . 这取决于你如何设置并且可能是痛苦和有问题的,例如Heroku 不是 长期请求的 忠实粉丝

  • Use a faster interpreter. 使用更快的解释器。

  • Faster hardware/VM. 更快的硬件/ VM。

Are you precompiling the assets in development? 您是否在开发中预编译资产?

bundle exec rake assets:precompile

That should keep the assets from recompiling each time. 这应该使资产不会每次重新编译。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM