无法阻止浏览器缓存页面

时间:2019-01-08 11:13:24

标签: ruby-on-rails

我试图防止浏览器缓存在表单页面上,并阻止用户在提交后返回。

application_controller.rb

protected

  def set_no_cache
    response.headers["Cache-Control"] = "no-cache, no-store, max-age=0, must-revalidate"
    response.headers["Pragma"] = "no-cache"
    response.headers["Expires"] = "Fri, 01 Jan 1990 00:00:00 GMT"
  end

another_controller.rb

before_filter :set_no_cache, only: [:new, :edit]

例如,当在“ edit”操作上添加byebug时,我会看到标题已正确更改:

(byebug) headers
{"X-Frame-Options"=>"SAMEORIGIN", "X-XSS-Protection"=>"1; mode=block", "X-Content-Type-Options"=>"nosniff", "Cache-Control"=>"no-cache, no-store, max-age=0, must-revalidate", "Pragma"=>"no-cache", "Expires"=>"Fri, 01 Jan 1990 00:00:00 GMT"}

但这对我不起作用,我尝试在适用于Chrome,Opera和Safari浏览器的Ubuntu上进行测试。

0 个答案:

没有答案