Cam*_*lle 23 gzip heroku ruby-on-rails-3.1 expires-header cedar
我在Heroku Cedar上运行Rails 3.1.1应用程序.默认情况下,此堆栈不会Gzip并在资产上设置Expires Headers.有一些关于这方面的文档,但它不是很清楚:http://devcenter.heroku.com/articles/http-routing
有人可以给我一段代码来激活吗?
非常感谢你
Duo*_*SRX 38
Cedar不使用Nginx,所以你必须使用Rack :: Deflater自己使用gzip资源,如下所示:
# config.ru
require ::File.expand_path('../config/environment', __FILE__)
use Rack::Deflater
run YourApp::Application
Run Code Online (Sandbox Code Playgroud)
您还可以直接在应用中为静态文件设置标题:
# config/environments/production.rb
config.static_cache_control = "public, max-age=3600"
Run Code Online (Sandbox Code Playgroud)
最后你可能最好设置Rack :: Cache来取代Varnish缓存.有关更多信息,请参阅此博客文章.
无耻的插件 - 我创建了一个可以压缩的宝石,但避免压缩图像.
https://github.com/romanbsd/heroku-deflater
重要的是要尽早将中间件包括在内 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
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
6387 次 |
| 最近记录: |