在Ruby on Rails 3中压缩资产 [英] Compressing assets in Ruby on Rails 3

查看:141
本文介绍了在Ruby on Rails 3中压缩资产的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在production.rb中有以下配置

I have following configurations in 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应用程序出现以下错误时:

But when the ruby on rails application on production server I get following error:

Error compiling CSS asset

LoadError: cannot load such file -- yui-compressor

在注释行LoadError: cannot load such file -- yui-compressor上,一切正常.
我只需要一个在发送前先gzip压缩资产的压缩器,以提高性能!
那么,这是什么问题,或者还有其他替代方法吗?

on commenting line LoadError: cannot load such file -- yui-compressor,everything goes well.
All I need a compressor that gzip compress assets before sending to improve performance!
so,what is problem here or is there any other alternative?



更新:
另外,javascript压缩不起作用,因为Firefox的yslow插件还显示需要压缩javascript.



Update:
Also javascript compression is not working,as yslow plugin for firefox also showing javascripts needs to be compressed.

推荐答案

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

I found that the compression must be enabled on webserver to have effect.
All that is needed is to add following:

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

对于我的情况,在<VirtualHost *:80></VirtualHost>指令中

适用于Apache(phusion乘客).

in <VirtualHost *:80></VirtualHost> directive for Apache(phusion passenger) for my case.

这篇关于在Ruby on Rails 3中压缩资产的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆