据我所知,在Rails 4中,除了Cache-Control
之外,无法在文件上设置其他响应头。那是一个限制。
不过,with changes in Rails 5可以设置任何所需的标头,并且这是进行开发的正确位置:config.public_file_server.headers
中的development.rb
但是,要使更改生效,必须在启动服务器之前使用rails dev:cache
create a development cache。
演示:
development.rb:
if Rails.root.join('tmp/caching-dev.txt').exist?
config.action_controller.perform_caching = true
config.cache_store = :dalli_store
config.public_file_server.headers = {
'Cache-Control' => 'public,max-age=172800','Accept-Ranges' => 'none'
}
else
config.action_controller.perform_caching = false
config.cache_store = :null_store
end
开发缓存和服务器
$ rails dev:cache
Development mode is now being cached.
$ rails s
请求:
$ curl -sI http://localhost:3000/car-images-silhouettes/back.png | grep Accept-Ranges
Accept-Ranges: none
本文链接:https://www.f2er.com/3132277.html