【问题标题】:Compressing assets in Ruby on Rails 3在 Ruby on Rails 3 中压缩资产
【发布时间】:2012-12-28 15:16:50
【问题描述】:

我在 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

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

Error compiling CSS asset

LoadError: cannot load such file -- yui-compressor

在评论行LoadError: cannot load such file -- yui-compressor,一切顺利。
我只需要一个压缩器,它可以在发送之前压缩资产以提高性能!
那么,这里有什么问题或者还有其他替代方法吗?



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

【问题讨论】:

    标签: ruby-on-rails asset-pipeline sprockets yui-compressor


    【解决方案1】:

    您是否在 Gemfile 中包含了 yui-compressor gem?如果没有,则包含它,运行 'bundle install',然后 Rails 应该能够找到它。

    【讨论】:

    • 是的,我在 Gemfile 和 run bundle install 中包含了 yui-compressor gem。irb 也显示相同的错误。
    【解决方案2】:

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

    AddOutputFilterByType DEFLATE text/html text/css application/x-javascript application/javascript
    

    <VirtualHost *:80></VirtualHost> 指令中针对我的情况为 Apache(phusion 乘客)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-04-13
      • 2012-11-23
      相关资源
      最近更新 更多