title: How to enable compression in Ruby on Rails?
body: <p>I posted a similar question here</p>
  
  <p><a href="https://stackoverflow.com/questions/25552802/serving-compressed-assets-in-heroku-with-rack-zippy">Serving Compressed Assets in Heroku with Rack-Zippy</a></p>
  
  <p>but decided to give up on that service, since I couldn't get it to work.</p>
  
  <p>I ran PageSpeed Insights on my website to determine the speed of my website.</p>
  
  <p>The most important suggestion I received was to Enable Compression.</p>
  
  <pre><code>Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.
  Enable compression for the following resources to reduce their transfer size by 191.2KiB 
  (74% reduction).
  </code></pre>
  
  <p>I've followed the instructions on this website</p>
  
  <p><a href="https://developers.google.com/speed/docs/insights/EnableCompression" rel="noreferrer">https://developers.google.com/speed/docs/insights/EnableCompression</a></p>
  
  <p>and it says to consult the documentation for your web server on how to enable compression:</p>
  
  <p>I've used this website to find out my web server</p>
  
  <p><a href="http://browserspy.dk/webserver.php" rel="noreferrer">http://browserspy.dk/webserver.php</a></p>
  
  <p>It turns out that my web server is WEBrick.</p>
  
  <p>The PageSpeed Insights Page only lists the following 3 servers</p>
  
  <pre><code>Apache: Use mod_deflate
  Nginx: Use ngx_http_gzip_module
  IIS: Configure HTTP Compression
  </code></pre>
  
  <p>I've searched for documentation on gzip compression for WEBrick servers but couldn't find anything.</p>
  
  <p>I've searched for how to enable compression in Rails and couldn't find anything. That's why I'm asking here.</p>
  
  <p>I've tried using Rack Zippy but gave up on it.</p>
  
  <p>Right now, I don't even know where to begin. My first step, is finding out what I should do.</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I followed Ahmed's suggestion of using Rack::Deflator</p>
  
  <p>I confirmed that I had it by running</p>
  
  <pre><code>rake middleware
  =&gt; use Rack::Deflator
  </code></pre>
  
  <p>and then</p>
  
  <pre><code>git add .
  git commit -m '-'
  git push heroku master
  </code></pre>
  
  <p>Unfortunately PageSpeed still says it needs to be compress. I confirmed that by going into Developer Tools &lt;&lt; Network Settings and refreshing the page. Size and content were virtually identical for every resource meaning the files are not compressed.</p>
  
  <p>Is there something wrong with one of my files?</p>
  
  <p>Thank you for your help.</p>
  
  <p>Here is my full config/application.rb file</p>
  
  <pre><code>require File.expand_path('../boot', __FILE__)
  
  require 'rails/all'
  
  Bundler.require(*Rails.groups)
  
  module AppName
    class Application &lt; Rails::Application
  
      config.middleware.use Rack::Deflater
      config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
      config.exceptions_app = self.routes
  
      config.cache_store = :memory_store
  
    end
  end
  </code></pre>
  
  <p>If there is a problem, the source is likely over there, right?</p>
  
  <p>Do I need to install the deflator gem?</p>