Skip to main content
BLOG.siposdani87

How to make Rails response faster

Boost your Rails performance with Brotli compression

By Dániel Sipos
· · 1 min read

The simplest way to improve your application’s response performance is to compress the data with Brotli.

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

Add the required gems to your Gemfile and run bundle install:

gem 'rack-deflater'
gem 'rack-brotli'

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

config.middleware.use Rack::Deflater
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.

Conclusion

Brotli compression offers better compression ratios than gzip with comparable decompression speed, making it an effective way to reduce response sizes and improve page load times in Rails applications.

References

Share with your friends

Related posts