禁用塔中的浏览器缓存 [英] Disable browser caching in pylons

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

问题描述

我有一个/json动作,它从服务器返回json.

I'm have an action /json that returns json from the server.

不幸的是,在IE中,浏览器喜欢缓存此json.

Unfortunately in IE, the browser likes to cache this json.

如何做到这一点,以使该操作不会被缓存?

How can I make it so that this action doesn't cache?

推荐答案

请确保您的响应不会告诉浏览器该内容将来会过期.有两个HTTP标头对此进行控制.

Make sure your responses are not telling the browser that the content expires in the future. There are two HTTP headers the control this.

  1. 到期
  2. Cache-Control-此标头有很多可能的值,但控制到期的值是max-age = foo.

此外,IE可能正在重新验证.这意味着IE在请求中包括一些额外的信息,这些信息告诉Web服务器其缓存中具有哪个版本的资源.如果浏览器的缓存版本为最新版本,则服务器可以使用304 Not Modified进行响应,并且不将内容包括在响应中. 条件GET请求"包括此版本信息.您的服务器有可能在不应该的时候给出304个响应.

In addition, IE may be revalidating. This means that IE includes some extra information in the request that tell the web server what version of the resource it has in its cache. If the browser's cached version is current, your server can respond with 304 Not Modified and NOT include the content in the responses. "Conditionatl GET requests" include this versioning information. It's possible that your server is giving 304 responses when it shouldn't be.

有两组控制重新验证的标头:

There are two sets of headers that control revalidation:

  1. 最后修改+如果修改后
  2. ETag +如果不匹配

Last-Modified和ETag是响应标头,它们告诉浏览器它将接收什么资源版本.如果您不希望浏览器重新验证,请不要进行设置. If-Modified-Since和If-None-Match是相应的请求标头,浏览器用来报告需要通过服务器重新验证的过时资源的版本.

Last-Modified, and ETag are response headers that tell the browser what the version of the resource it is about to receive. If you don't want browsers to revalidate, don't set these. If-Modified-Since and If-None-Match are the corresponding request headers that the browser uses to report the version of a stale resource that it needs to revalidate with the server.

有多种工具可以查看服务器将哪些HTTP标头发送回浏览器.一个是Firefox扩展实时HTTP标头. 史蒂夫测深仪推荐的另一种工具是

There are various tools to see what HTTP headers your server is sending back to the browser. One is the Firefox extension Live HTTP Headers. Another tool, which Steve Sounders recommends is IBM Page Detailer. I haven't tried this one myself, but it doesn't depend on the browser that you're using.

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

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