如何使用 Rails 对网页输出进行 gzip 压缩?

发布于 2024-07-07 19:05:12 字数 128 浏览 6 评论 0原文

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

随风而去 2024-07-14 19:05:12

您测试过它是否已启用吗? 如果您的托管提供商使用 Apache,那么默认情况下它可能就在那里。

对您的网站运行此命令,看看是否获得 Content-Encoding: gzip 标头。

$ curl --head -H "Accept-Encoding: gzip" http://example.com

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
帅哥哥的热头脑 2024-07-14 19:05:12

除非您在没有其他 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.

不再让梦枯萎 2024-07-14 19:05:12

您是否尝试过使用 deflate 中间件? 将 use Rack::Deflater 添加到您的 config.ru 中。

这就是你如何使用在 Heroku 上运行的应用程序来做到这一点(自 cedar-stack 以来)。

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

撩起发的微风 2024-07-14 19:05:12

如果您的托管公司不支持 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.

丶情人眼里出诗心の 2024-07-14 19:05:12

您是否尝试过通过 mod_deflate 在 apache 中启用压缩?

Have you tried enabling compression in apache via mod_deflate?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文