1

I'm running some audits in my open-source project, BTC-Stores, and some times Chrome shows me that I need "Enable Gzip compression".

Sometime ago I read "High Performance Websites", from Steve Souders, and I already know the basic concepts about how make your page load faster. My project is using Ruby 2.0.0 and Rails 4.

I want know, Rails 4 already have a "gzip like compression" or I need to activate it by some gem or config? If you can, please link some good articles about Rails 4 performance and how to optimize it.

Baldrick
  • 23,882
  • 6
  • 74
  • 79
Paladini
  • 4,522
  • 15
  • 53
  • 96

2 Answers2

2

Here's some more about using gzip with Rails!

From http://guides.rubyonrails.org/asset_pipeline.html:

4.1.2 GZip Compression

When files are precompiled, Sprockets also creates a gzipped (.gz) version of your assets. Web servers are typically configured to use a moderate compression ratio as a compromise, but since precompilation happens once, Sprockets uses the maximum compression ratio, thus reducing the size of the data transfer to the minimum. On the other hand, web servers can be configured to serve compressed content directly from disk, rather than deflating non-compressed files themselves.

Nginx is able to do this automatically enabling gzip_static:

location ~ ^/(assets)/ { root /path/to/public; gzip_static on; # to serve pre-gzipped version expires max; add_header Cache-Control public; } This directive is available if the core module that provides this feature was compiled with the web server. Ubuntu packages, even nginx-light have the module compiled. Otherwise, you may need to perform a manual compilation:

./configure --with-http_gzip_static_module If you're compiling nginx with Phusion Passenger you'll need to pass that option when prompted.

A robust configuration for Apache is possible but tricky; please Google around. (Or help update this Guide if you have a good example configuration for Apache.)

Also, the following may be of interest!

http://api.rubyonrails.org/classes/ActiveSupport/Gzip.html

Hope this helps!

Drew
  • 2,583
  • 5
  • 36
  • 54
  • Thanks! I will give you the best answer because your post have a link that I can follow and read about Gzip in Rails. :) – Paladini Jan 16 '14 at 01:51
1

Yes you need to use Gzip in a Rails 4 or any other project. You do that in the production server and not on your local.

Duplicated question: Compressing rails assets and nginx gzip (with nginx server)

Community
  • 1
  • 1
Michael Koper
  • 9,586
  • 7
  • 45
  • 59