在Ruby on Rails中压缩资产3

Chi*_*ani 5 ruby-on-rails yui-compressor sprockets asset-pipeline

我在production.rb中有以下配置

 # Disable Rails's static asset server (Apache or nginx will already do this)
  config.serve_static_assets = false

  # Compress JavaScripts and CSS
  config.assets.compress = true

  # Choose the compressors to use
  config.assets.js_compressor  = :uglifier
  config.assets.css_compressor = :yui

  # Don't fallback to assets pipeline if a precompiled asset is missed
  config.assets.compile = true

  # Generate digests for assets URLs.
  config.assets.digest = true
Run Code Online (Sandbox Code Playgroud)

但是当生产服务器上的ruby on rails应用程序出现以下错误:

Error compiling CSS asset

LoadError: cannot load such file -- yui-compressor
Run Code Online (Sandbox Code Playgroud)

在评论线上LoadError: cannot load such file -- yui-compressor,一切顺利.
所有我需要一个压缩机,gzip压缩资产之前发送,以提高性能!
那么,这里有什么问题或者还有其他选择吗?



更新:
javascript压缩也不起作用,因为firefox的yslow插件也显示javascripts需要压缩.

Kyr*_*lia 7

你在你的Gemfile中包含了yui-compressor gem吗?如果没有,那么包括它,运行'bundle install',然后Rails应该能够找到它.


Chi*_*ani 3

我发现必须在网络服务器上启用压缩才能生效。
所需要做的就是添加以下内容:

AddOutputFilterByType DEFLATE text/html text/css application/x-javascript application/javascript
Run Code Online (Sandbox Code Playgroud)

<VirtualHost *:80></VirtualHost>对于我的情况,在Apache(phusion Passenger) 指令中。