禁用浏览器缓存为后退按钮? [英] disable browser cache for back button?

查看:158
本文介绍了禁用浏览器缓存为后退按钮?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

  self.set_header(Cache-Control,no -cache,must-revalidate,max-age = 0)
self.set_header(Expires,Mon,1997年7月26日05:00:00 GMT)


这是我在第一次加载页面时从firebug看到的内容:

pre > Cache-Control no-cache,must-revalidate,max-age = 0
Content-Length 1715
Content-Type text / html; charset = UTF-8
Etage55dc7115d80aa09b470510ababb3515706f4a61
过期时间1997年7月26日星期一05:00:00 GMT
服务器TornadoServer / 2.3
Set-Cookie xsfr = 5b7f3cf86c2e4537acd1bb1749484a5b; Path = /

然而,当我按BACK按钮返回到原始URL时,页面的缓存版本!该页面不从服务器重新获取。结果是它包含无效的隐藏表单值。无论用户如何填写表单,都无法处理。



这个问题可以在firefox和chrome上复制,但不能从IE浏览器中复制。

强制firefox和铬来禁用缓存,并重新加载页面,每当按下后退按钮?

解决方案

我不知道是否你解决了这个问题,但是我昨晚面临同样的问题。 这个回答在一定程度上对我有所帮助。我通过设置标题和清除用户cookie来解决这个问题。



下面是我做的一个要点:

  class BaseHandler tornado.web.RequestHandler):

def set_default_headers(self):
self.set_header('Cache-Control','no-cache,no-store,must-revalidate')
self.set_header('Pragma','no-cache')
self.set_header('Expires','0')



现在SignOut处理程序:
$ b $ pre $ class $ SignOut(BaseHandler)

def get(self):
self.clear_cookie(user)
self.redirect('/')

user是cookie集的名称。


This is what I have tried from Python/tornadoweb:

    self.set_header("Cache-Control","no-cache, must-revalidate, max-age=0")
    self.set_header("Expires","Mon, 26 Jul 1997 05:00:00 GMT")

This is what I see from firebug when I first load the page:

Cache-Control   no-cache, must-revalidate, max-age=0
Content-Length  1715
Content-Type    text/html; charset=UTF-8
Etag    "e55dc7115d80aa09b470510ababb3515706f4a61"
Expires Mon, 26 Jul 1997 05:00:00 GMT
Server  TornadoServer/2.3
Set-Cookie  xsfr=5b7f3cf86c2e4537acd1bb1749484a5b; Path=/

And yet, when I press BACK button to go back to the original URL, I get a cached version of the page! The page is not re-fetched from the server. The result is that it contains invalid hidden form values. No matter how the user fills in the form, it cannot be processed.

The problem can be reproduced on firefox and chrome, but not from internet explorer.

So, how to force firefox and chrome to disable the cache and reload the page whenever the back button is pressed?

解决方案

I don't know if you solved this issue or not, but I faced the same issue last night. This answer helped me to some extent. I solved it by setting the header and clearing the user cookie.

Here's a gist of what I did :

class BaseHandler(tornado.web.RequestHandler):

    def set_default_headers(self):
        self.set_header('Cache-Control', 'no-cache, no-store, must-revalidate')
        self.set_header('Pragma', 'no-cache')
        self.set_header('Expires', '0')

Now the SignOut handler :

class SignOut(BaseHandler):

    def get(self):
        self.clear_cookie("user")
        self.redirect('/')

"user" is the name of the cookie set.

这篇关于禁用浏览器缓存为后退按钮?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆