簡體   English   中英

在RAILS 3.1中的js資產上設置Cache-Control標頭

[英]Setting Cache-Control headers on js assets in RAILS 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上刷新。 關於如何獲得這個的任何想法?

布拉德

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

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

Camille的答案適用於5.1之前的Rails版本

但是, 在Rails 5.1中,不推薦使用config.static_cache_control 使用新的可用選項更新的代碼應為:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM