how to verify “Cache-Control”, “no-cache, no-store, must-revalidate”

◇◆丶佛笑我妖孽 提交于 2019-12-10 10:51:30

问题


I am learning about cache and how to manage it.

I can see that static content like images, css files, js files gets stored in temporary folder when I open my website pages. But now when I added these attributes in response header, I cannot see any changes in cache behaviour.

All content is getting stored like before. And even when I am making some changes in js files, I cannot see new js files being fetched. Browser uses the same old js files with outdated content.

So am I doing something wrong.

Logic that I added in JSP file :

    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.

After these changes :

Response Headers

     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

Before these changes:

Response Headers

    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

I just wanted to know that how can I verify that these headers are working properly. Any help would be appreciated.


回答1:


Install LiveHTTPHeaders in Chrome and you can see all the headers in the page. You can also do it the hard way and use a pcap tool like tcpdump or Wireshark to see the requested packets and view the headers.




回答2:


Using curl:

curl -I  "URL"

The -I flag will show the headers.



来源:https://stackoverflow.com/questions/27444799/how-to-verify-cache-control-no-cache-no-store-must-revalidate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!