如何使用 Rails 对网页输出进行 gzip 压缩?
gzips 我的网页输出最好的 Rails 插件是什么?
编辑: 我托管的公司已声明他们不会安装 mod_deflate
。
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
.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
您测试过它是否已启用吗? 如果您的托管提供商使用 Apache,那么默认情况下它可能就在那里。
对您的网站运行此命令,看看是否获得
Content-Encoding: gzip
标头。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.除非您在没有其他 Web 服务器的情况下运行 Rails 应用程序(这通常不是一个好主意),否则您可能应该查看您的 Web 服务器。 所有主要网络服务器都有启用 gzip 的选项。 例如,对于 Apache,您可以使用 mod_deflate。
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.
您是否尝试过使用 deflate 中间件? 将
use Rack::Deflater
添加到您的config.ru
中。这就是你如何使用在 Heroku 上运行的应用程序来做到这一点(自 cedar-stack 以来)。
Have you tried using the deflate middleware? Add
use Rack::Deflater
to yourconfig.ru
.It's how you'd do it with an app running on Heroku (AFAIK since cedar-stack).
如果您的托管公司不支持 mod_deflate,那么是时候换一家新的托管公司了。 我认为在 Ruby 中这样做会非常慢而且很痛苦。
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.
您是否尝试过通过 mod_deflate 在 apache 中启用压缩?
Have you tried enabling compression in apache via mod_deflate?