How do I gzip webpage output with Rails?

左心房为你撑大大i 提交于 2019-12-17 16:06:35

问题


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.


回答1:


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.




回答2:


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



回答3:


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).




回答4:


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.




回答5:


Have you tried enabling compression in apache via mod_deflate?



来源:https://stackoverflow.com/questions/250566/how-do-i-gzip-webpage-output-with-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!