What is Gzip Compression?
Gzip compression is a quick and easy way to speed up the loading times of your web application. This can be done by compressing the static assets like stylesheets, javascripts, etc before serving them to the web browser. This can save a lot of bandwidth and as well as make your webpages load really fast. Gzip compression is done on the server side and then compressed assets are sent to the web browser.
Enabling Gzip
Gzip compression can easily be enabled on rails using Rack Deflater.
Rack Deflater Rybydoc: https://www.rubydoc.info/gems/rack/Rack/Deflater
To enable it, just open config/application.rb and add the following.
#File: config/application.rb
require_relative "boot"
require "rails/all"
Bundler.require(*Rails.groups)
module Myapp
class Application < Rails::Application
config.load_defaults 6.1
config.middleware.use Rack::Deflater
end
end
This config: config.middleware.use Rack::Deflater
will enable rack deflater
Final Thoughts
Your app will now compress all static assets and serve them. You should now see an improvement in loading times of your application. That’s all folks, have a nice day.