我在Heroku Cedar上运行Rails 3.1.1应用程序。默认情况下,此堆栈不会Gzip并在 assets 上设置Expires Headers。有一些关于此的文档,但不是很清楚:http ://devcenter.heroku.com/articles/http-routing
有人可以给我一段代码来激活它吗?
非常感谢你
我在Heroku Cedar上运行Rails 3.1.1应用程序。默认情况下,此堆栈不会Gzip并在 assets 上设置Expires Headers。有一些关于此的文档,但不是很清楚:http ://devcenter.heroku.com/articles/http-routing
有人可以给我一段代码来激活它吗?
非常感谢你
Cedar 不使用 Nginx,因此您必须自己使用 Rack::Deflater 压缩资源,如下所示:
# config.ru
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run YourApp::Application
您还可以直接在您的应用程序中设置静态文件的标题:
# config/environments/production.rb
config.static_cache_control = "public, max-age=3600"
最后,您最好设置Rack::Cache来替换 Varnish 缓存。有关更多信息,请参阅此博客文章。
无耻插件 - 我创建了一个可以压缩但避免压缩图像的 gem。
尽早包含中间件很重要,之前ActionDispatch::Static
#production.rb
config.middleware.insert_before ActionDispatch::Static, Rack::Deflater
> rake middleware
use Rack::Deflater
use ActionDispatch::Static
use Rack::Lock
use #<ActiveSupport::Cache::Strategy::LocalCache::Middleware:0x007f8e18455e90>
use Rack::Runtime
use Rack::MethodOverride
use ActionDispatch::RequestId
use Rails::Rack::Logger
use ActionDispatch::ShowExceptions
use ActionDispatch::DebugExceptions
use ActionDispatch::RemoteIp
use ActionDispatch::Reloader
use ActionDispatch::Callbacks
use ActionDispatch::Cookies
use ActionDispatch::Session::CookieStore
use ActionDispatch::Flash
use ActionDispatch::ParamsParser
use Remotipart::Middleware
use ActionDispatch::Head
use Rack::ConditionalGet
use Rack::ETag
use ActionDispatch::BestStandardsSupport
use Warden::Manager
use Rack::Mongoid::Middleware::IdentityMap
use Rack::Pjax
run MyApp::Application.routes