2011-06-22 50 views
6

檢查我的生產服務器上的標題爲設置的Cache-Control頭鋼軌3.1

curl --head -H "Accept-Encoding: gzip" http://foo.heroku.com/assets/mobile.js 

,我得到以下標題這表明Rails是不設置cachecontrol頭。

HTTP/1.1 200 OK 
Server: nginx/0.7.67 
Date: Wed, 22 Jun 2011 12:01:55 GMT 
Content-Type: application/javascript 
Connection: keep-alive 
Content-Md5: efb90436a465f8a73efb467109f745f3 
Cache-Control: no-cache 
Last-Modified: Wed, 22 Jun 2011 11:46:04 GMT 
Etag: "efb90436a465f8a73efb467109f745f3" 
X-Ua-Compatible: IE=Edge,chrome=1 
X-Runtime: 0.001258 
X-Content-Digest: 6493f457e9550773761bb1c2c52ec4cb44a19c19 
X-Rack-Cache: stale, valid, store 
X-Varnish: 164373614 
Age: 0 
Via: 1.1 varnish 
Content-Encoding: gzip 

我想讓heroku的清漆緩存緩存資產,只刷新git push。任何想法如何得到這個?

布拉德

+0

本文應該闡明一些問題:http://jimmycuadra.com/posts/the-challenge-of-asset-packaging-on-heroku –

回答

7

您必須在您的環境/ production.rb補充一點:

config.serve_static_assets = true 
config.static_cache_control = "public, max-age=172800" 
+1

甚至3年後,您用'config.static_cache_control'完成了我的一天,謝謝 –

1

Camille的答案是正確的爲Rails之前的版本5.1

然而,用Rails 5.1config.static_cache_control將被棄用。代碼更新與新的可用選項應該是:

config.serve_static_assets = true 
config.public_file_server.headers = { 'Cache-Control' => 'public, max-age= 172800' }