Skip to content
Menu
Railshero
  • Blog
  • About Me
  • Contact Me
  • Privacy Policy
Railshero
Enabling Gzip Compression

Enabling Gzip Compression in your rails apps

Posted on September 26, 2021September 26, 2021 by Rails Hero

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

Gzip Enabled
Gzip Enabled

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.

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Tags

active storage activity logging administration admin panel analyze assets assign to many attachment attachments authentication authorization avatar bootstrap cdn deployments devise dislikes environment variables file uploads file validation Gemfile gems heroku index indexing initializer javascript likes links pagination parameters pipeline production routes.rb ruby gem ruby gems search sendgrid smtp spectrum stylesheets variants views visualize voting

Recent Posts

  • Open Source Web Icons
  • Devise tutorial: adding avatars with active storage
  • SEO friendly URLs with friendly_id
  • Heroku Environment Variables
  • Enabling Gzip Compression in your rails apps

Archives

  • October 2021
  • September 2021
  • August 2021
  • July 2021

Categories

  • Activity Logging
  • Apps
  • Assets
  • Attachments
  • Audio
  • Authentication
  • Authorization
  • Deployments
  • Error Pages
  • File Uploads
  • General
  • Heroku
  • Heroku
  • Pagination
  • RubyGems
  • Search Engine Optimization
  • Search/Indexing
  • User Interface
  • Video
  • Voting
©2026 Railshero | Theme: Wordly by SuperbThemes
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept All”, you consent to the use of ALL the cookies. However, you may visit "Cookie Settings" to provide a controlled consent.
Cookie SettingsAccept All
Manage consent

Privacy Overview

This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary
Always Enabled
Necessary cookies are absolutely essential for the website to function properly. This category only includes cookies that ensures basic functionalities and security features of the website. These cookies do not store any personal information.
Non-necessary
Any cookies that may not be particularly necessary for the website to function and is used specifically to collect user personal data via analytics, ads, other embedded contents are termed as non-necessary cookies. It is mandatory to procure user consent prior to running these cookies on your website.
SAVE & ACCEPT