在RAILS 3.1中的js资产上设置Cache-Control标头

bra*_*ing 7 javascript caching ruby-on-rails heroku ruby-on-rails-3.1

我检查生产服务器上的标题为

    curl --head -H "Accept-Encoding: gzip" http://foo.heroku.com/assets/mobile.js
Run Code Online (Sandbox Code Playgroud)

然后我回到以下标题,建议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
Run Code Online (Sandbox Code Playgroud)

我想让heroku的清漆缓存缓存资产,只在git push上刷新.关于如何获得这个的任何想法?

布拉德

Cam*_*lle 9

您必须在您的environment/production.rb中添加它:

config.serve_static_assets = true
config.static_cache_control = "public, max-age=172800"
Run Code Online (Sandbox Code Playgroud)

  • 甚至3年后,您还是用`config.static_cache_control`来度过了我的一天。 (2认同)