views:

453

answers:

2

I have a rails app that uses heavily js (over 1MB total). I'd like to compress them in order to reduce the overall load time of the site.

I did a fast search and found that most browsers accept compressed content.

I'd like to know what can I do to make my rails app send compressed content and thus make the user experience better.

+3  A: 

You should always have the web server proxying to your mongrels handle the serving of static content and it's compression. Requests for static content should never be passed to the mongrels.

e.g. with nginx it's simply a matter of adding gzip directives to your config file.

http://topfunky.net/svn/shovel/nginx/conf/nginx.conf

# output compression saves bandwidth 
  gzip            on;
  gzip_http_version 1.0;
  gzip_comp_level 2;
  gzip_proxied any;
  gzip_types      text/plain text/html text/css application/x-javascript text/xml application/xml application/xml+rss text/javascript;
Michael
+1  A: 

Two similar questions have been asked and answered. Hopefully the content there will be helpful, too.

How can I pre-compress files with mod_deflate in Apache 2.x?

How do I gzip webpage output with Rails?

Otto