How to make Rails response faster

Boost your Rails performance with Brotli compression
By: Dániel Sipos on

The simpliest way to gain your app response performance is compress the data with (brotli)[]

To make your Rails response faster with Brotli, you can follow these steps:

Install the rack-deflater gem:

gem install rack-deflater

Add the rack-deflater gem to your Gemfile and run bundle install:

gem 'rack-deflater'

In your config/application.rb file, add the following line to enable the middleware:

config.middleware.use Rack::Deflater

In your config/environments/production.rb file, add the following line to set the Content-Encoding header to br:

config.middleware.insert_before Rack::Deflater, Rack::Brotli

Precompile your assets by running the following command:

RAILS_ENV=production rake assets:precompile

This will compress your assets using Brotli and serve them with the Content-Encoding: br header, which will allow browsers that support Brotli to decompress the response and improve the loading time of your website.

Share with your friends

Related posts