我正在学习缓存以及如何管理它。
当我打开网站页面时,我可以看到图像、css 文件、js 文件等静态内容存储在临时文件夹中。但现在,当我在响应 header 中添加这些属性时,我看不到缓存行为的任何变化。
所有内容都像以前一样存储。即使我在 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.
进行这些更改后:
响应 header
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
这些更改之前:
响应 header
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
我只是想知道如何验证这些 header 是否正常工作。任何帮助将不胜感激。
最佳答案
在Chrome中安装LiveHTTPHeaders,您就可以看到页面中的所有 header 。您还可以通过困难的方式来完成此操作,并使用 tcpdump 或 Wireshark 等 pcap 工具来查看请求的数据包并查看 header 。
关于javascript - 如何验证 "Cache-Control"、 "no-cache, no-store, must-revalidate",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27444799/