How do I gzip webpage output with Rails?
Asked Answered
L

5

15

What is the best plugin for Rails that gzips my webpage output?

Edit: The company I am hosting with has stated they will not install mod_deflate.

Lam answered 30/10, 2008 at 15:20 Comment(0)
B
12

Unless you are running your Rails application without another webserver (which usually isn't a great idea), you should probably look at your webserver. All major webservers have options to enable gzip. For example, for Apache, you can use mod_deflate.

Backstage answered 30/10, 2008 at 15:34 Comment(0)
D
13

Have you tested to see if it's already enabled? If your hosting provider uses Apache it very well could be there by default.

Run this command against your site and see if you get the Content-Encoding: gzip header.

$ curl --head -H "Accept-Encoding: gzip" http://example.com
Ddene answered 30/10, 2008 at 15:20 Comment(0)
B
12

Unless you are running your Rails application without another webserver (which usually isn't a great idea), you should probably look at your webserver. All major webservers have options to enable gzip. For example, for Apache, you can use mod_deflate.

Backstage answered 30/10, 2008 at 15:34 Comment(0)
V
4

Have you tried using the deflate middleware? Add use Rack::Deflater to your config.ru.

It's how you'd do it with an app running on Heroku (AFAIK since cedar-stack).

Vigilance answered 14/12, 2012 at 10:43 Comment(1)
config.middleware.insert_before 'ActionDispatch::Static', 'Rack::Deflater'Burress
P
3

If your hosting company does not support mod_deflate it's time for a new hosting company. I think doing this in Ruby would be pretty slow and a pain in the butt.

Pillsbury answered 31/10, 2008 at 17:2 Comment(1)
How would that be different from everything else in rails :) Ha ha.. Seriously couldn't resist. I tried but I couldn't :)Ileenileitis
T
0

Have you tried enabling compression in apache via mod_deflate?

Theoretical answered 30/10, 2008 at 15:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.