【发布时间】:2014-08-29 21:20:40
【问题描述】:
我在这里发布了一个类似的问题
Serving Compressed Assets in Heroku with Rack-Zippy
但决定放弃这项服务,因为我无法让它发挥作用。
我在我的网站上运行 PageSpeed Insights 以确定我的网站的速度。
我收到的最重要的建议是启用压缩。
Compressing resources with gzip or deflate can reduce the number of bytes sent over the network.
Enable compression for the following resources to reduce their transfer size by 191.2KiB
(74% reduction).
我已按照本网站上的说明进行操作
https://developers.google.com/speed/docs/insights/EnableCompression
它说要查阅您的 Web 服务器的文档以了解如何启用压缩:
我已使用此网站查找我的网络服务器
http://browserspy.dk/webserver.php
原来我的网络服务器是WEBrick。
PageSpeed Insights Page 仅列出以下 3 台服务器
Apache: Use mod_deflate
Nginx: Use ngx_http_gzip_module
IIS: Configure HTTP Compression
我搜索了有关 WEBrick 服务器的 gzip 压缩的文档,但找不到任何东西。
我搜索了如何在 Rails 中启用压缩,但找不到任何东西。这就是我在这里问的原因。
我尝试过使用 Rack Zippy 但放弃了。
现在,我什至不知道从哪里开始。我的第一步是找出我应该做什么。
编辑
我按照 Ahmed 的建议使用 Rack::Deflator
我通过运行确认我拥有它
rake middleware
=> use Rack::Deflator
然后
git add .
git commit -m '-'
git push heroku master
不幸的是,PageSpeed 仍然说它需要压缩。我通过进入开发者工具
我的某个文件有问题吗?
感谢您的帮助。
这是我的完整 config/application.rb 文件
require File.expand_path('../boot', __FILE__)
require 'rails/all'
Bundler.require(*Rails.groups)
module AppName
class Application < Rails::Application
config.middleware.use Rack::Deflater
config.assets.precompile += %w(*.png *.jpg *.jpeg *.gif)
config.exceptions_app = self.routes
config.cache_store = :memory_store
end
end
如果有问题,源头应该在那边吧?
我需要安装 deflator gem 吗?
【问题讨论】:
标签: ruby-on-rails ruby performance gzip pagespeed