禁用客户端缓存的最佳方法 [英] Best way to disable client caching
问题描述
我正在使用一个简单的servlet过滤器,强制浏览器跳过某些服务器资源的缓存:
I'm using a simple servlet filter that forces the browser to skip caching for some server resources:
Cache-Control: private
Pragma:
这在Internet Explorer中运行良好,但在Firefox 3.0.10中效果不佳。我结束了写这段代码:
This works fine in Internet Explorer but it doesn't works well with Firefox 3.0.10. I ended to write this code:
Cache-Control: no-cache, no-store, must-revalidate, max-age=-1
Pragma: no-cache, no-store
Expires: -1 // -1 is the unix time, the client receives a date in 1969 :)
Last-Modified: -1 // ditto
这会强制firefox不进行任何缓存。其他浏览器怎么样?没有适用于主流浏览器的缓存标头的最佳实践怎么样?
this forces firefox to cache nothing. What about other browsers? What about best practices on no caching headers that works on major browsers?
推荐答案
Drupal 6这样做(适用于我所知道的每个浏览器):
Drupal 6 does this (which works in every browser known by me):
- 到期:Sun,1978年11月19日05:00:00 GMT
- Last-Modified :星期五,2009年6月12日08:01:46 GMT(实际修改日期)
- 缓存控制:存储,无缓存,必须重新验证,后检查= 0,预检查= 0
- Expires: Sun, 19 Nov 1978 05:00:00 GMT
- Last-Modified: Fri, 12 Jun 2009 08:01:46 GMT (the actual modification date)
- Cache-Control: store, no-cache, must-revalidate, post-check=0, pre-check=0
此实例中没有pragma标头。我不确定为什么你的例子不起作用,它可能是负时间戳,这适用于~250.000 Drupal网站:)
No pragma header in this instance. I'm not sure why your example doesn't work, it might be the negative timestamps, this works on ~250.000 Drupal sites :)
这篇关于禁用客户端缓存的最佳方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!