我在这里发布了类似的问题
使用 Rack-Zippy 在 Heroku 中提供压缩资源 https://stackoverflow.com/questions/25552802/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 https://developers.google.com/speed/docs/insights/EnableCompression
它说要查阅您的网络服务器的文档以了解如何启用压缩:
我使用这个网站来查找我的网络服务器
http://browserspy.dk/webserver.php http://browserspy.dk/webserver.php
原来我的网络服务器是WEBrick。
PageSpeed Insights 页面仅列出以下 3 台服务器
Apache: Use mod_deflate
Nginx: Use ngx_http_gzip_module
IIS: Configure HTTP Compression
我搜索了有关 WEBrick 服务器的 gzip 压缩的文档,但没有找到任何内容。
我搜索了如何在 Rails 中启用压缩,但找不到任何内容。这就是我在这里问的原因。
我尝试过使用 Rack Zippy 但放弃了。
现在,我什至不知道从哪里开始。我的第一步,是找出我应该做什么。
Edit
我遵循艾哈迈德使用 Rack::Deflator 的建议
我通过运行确认了它
rake middleware
=> use Rack::Deflator
and then
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 吗?