在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推送上刷新。有什么想法吗?
Brad
您必须将其添加到您的环境/生产中。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' }
相关文章:
- 如何解决Access Control Allow Origin错误
- 由于响应中不存在“Access Control Allow Origin”标头,跨域请求停止工作
- 调用Activex Control's javascript中的函数
- Angular Cache $resource Result
- 编辑输出字符串函数ol.control.MouseControl
- Chrome离线不会使用cache.manifest
- XMLHttpRequest : 不被 access-control-allow-origin 所允许
- tinyMCE不会添加特定文本区域的Control
- jQuery ajax cache response
- 可以在Access Control Allow Origin中指定端口
- angular google maps TypeError:$scope.map.control.refresh不是函数
- 使用jQuery重复Control
- Access Control Allow Origin阻止我访问google api,尽管使用了dataType:
- JSONP跨原点错误'不存在Access Control Allow Origin标头'
- 角度:原点http://localhost在Access Control Allow Origin标头中找不到
- Angular$resource调用不被Access Control Allow使用Safari接受,而被Chrome接
- 在传单中创建自定义control.layers类
- 即使设置了“Cache-Control: max-age”,浏览器是否继续发送资源请求?
- Firefox live http头,在Cache-Control: no-cache后面加大括号
- 在RAILS 3.1中设置js资产的Cache Control头