Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compressing assets in Ruby on Rails 3

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

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

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?



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

like image 867
Chirag Rupani Avatar asked Dec 27 '12 11:12

Chirag Rupani


2 Answers

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

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

like image 32
Chirag Rupani Avatar answered Sep 30 '22 09:09

Chirag Rupani


Have you included the yui-compressor gem in your Gemfile? If not, then include it, run 'bundle install', and then Rails should be able to find it.

like image 81
Kyri Elia Avatar answered Sep 30 '22 10:09

Kyri Elia