【问题标题】:how to verify "Cache-Control", "no-cache, no-store, must-revalidate"如何验证“缓存控制”、“无缓存、无存储、必须重新验证”
【发布时间】:2014-12-12 13:34:07
【问题描述】:

我正在学习缓存以及如何管理它。

当我打开我的网站页面时,我可以看到图像、css 文件、js 文件等静态内容存储在临时文件夹中。但是现在当我在响应头中添加这些属性时,我看不到缓存行为的任何变化。

所有内容都像以前一样存储。即使我对 js 文件进行了一些更改,我也看不到新的 js 文件正在被获取。浏览器使用相同的旧 js 文件,但内容已过时。

所以我做错了什么。

我在 JSP 文件中添加的逻辑:

    response.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP1.1.

    response.setDateHeader("Expires", 0); // Proxies.

  response.setHeader("Pragma", "no-cache"); // HTTP 1.0.

这些变化之后:

响应标头

     Cache-Control:no-cache, no-store, must-revalidate

    Content-Language:en-US

    Content-Length:3333

    Content-Type:text/html;charset=ISO-8859-1

    Date:Fri, 12 Dec 2014 11:48:37 GMT

    Expires:Thu, 01 Jan 1970 00:00:00 GMT

    Pragma:no-cache

    Server:WebSphere Application Server/8.0

    X-Powered-By:Servlet/3.0

在这些更改之前:

响应标头

    Content-Language:en-US

    Content-Length:6788

    Content-Type:text/html;charset=ISO-8859-1

    Date:Fri, 12 Dec 2014 11:50:10 GMT

    Server:WebSphere Application Server/8.0

    X-Powered-By:Servlet/3.0

我只是想知道如何验证这些标头是否正常工作。任何帮助将不胜感激。

【问题讨论】:

    标签: javascript html css caching no-cache


    【解决方案1】:

    在 Chrome 中安装 LiveHTTPHeaders,你可以看到页面中的所有 headers。您也可以通过艰难的方式来做,并使用 tcpdump 或 Wireshark 之类的 pcap 工具来查看请求的数据包并查看标头。

    【讨论】:

      【解决方案2】:

      使用curl

      curl -I  "URL"
      

      -I 标志将显示标题。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2012-04-17
        • 2012-08-20
        • 1970-01-01
        • 1970-01-01
        • 2017-11-20
        • 1970-01-01
        • 2014-04-22
        相关资源
        最近更新 更多