【问题标题】:Django Cache-control header: Why isn't Chrome caching this resource?Django Cache-control 标头:为什么 Chrome 不缓存此资源?
【发布时间】:2014-02-13 03:33:36
【问题描述】:

我已经用cache_control 装饰了一个 Django 视图,如下所示:

@cache_control(
    private=True,
    max_age=5 * 60,  # 5 minutes
)
def my_view(req):
    …

当我在本地测试服务器上尝试时,它按预期工作:Chrome 中的后续页面视图使用缓存的资源并且不发出请求。但是,在生产环境中部署时,Chrome 似乎会忽略 Cache-control 标头,并且每次我点击该页面时都会发出一个新请求。

这是生产服务器响应的标头的完整列表:

Cache-Control:private, max-age=300
Connection:close
Content-Encoding:gzip
Content-Length:13135
Content-Type:text/html; charset=utf-8
Date:Wed, 22 Jan 2014 20:39:29 GMT
P3P:CP="IDC CURa ADMa OUR IND PHY ONL COM STA"
Server:nginx/1.4.1
Set-Cookie:csrftoken=87y26bT5uPmyA9wt51N7m4blyqBH5nSo; expires=Wed, 21-Jan-2015 20:39:29 GMT; Max-Age=31449600; Path=/
Vary:Cookie,Accept-Encoding

可能出了什么问题?有任何想法吗?提前致谢!

【问题讨论】:

    标签: django google-chrome caching http-headers browser


    【解决方案1】:

    知道了:它是 Google Analytics 的 cookie 和 Vary:Cookie 标头(由 Django 的 SessionMiddleware 设置)的组合。 Analytics 的 cookie 随每个请求而变化,但由于在处理 localhost 时不会加载 ga.js,因此问题只出现在生产环境中。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-04-04
      • 2016-08-14
      • 1970-01-01
      • 2017-07-27
      • 2011-08-13
      • 2021-04-09
      • 2023-03-31
      相关资源
      最近更新 更多