HTTP 缓存控制
我正在为此苦苦挣扎- 在 PHP 中,我为 GET AJAX 调用执行此操作
header('Cache-Control: max-age = 10000, private');
此后浏览器仍然设法发出请求?为什么?
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 10000) . ' GMT');
不过效果很好!
谢谢
编辑
header("Cache-Control: private, max-age=10000");
似乎有效!
更多
规范是明确说明这一点。
cache-directive = cache-request-directive | cache-response-directive
http://www.w3.org/Protocols/rfc2616/rfc2616 -sec14.html#sec14.9.1
I am struggling with this -
In PHP, I do this for a GET AJAX call
header('Cache-Control: max-age = 10000, private');
The browser still manages to place a request thereafter? Why?
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + 10000) . ' GMT');
works fine, though!
Thanks
EDIT
header("Cache-Control: private, max-age=10000");
seems to work!!
MORE
The specification is explicit about this.
cache-directive = cache-request-directive | cache-response-directive
http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.9.1
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你用Firebug吗?如果是,则在页面加载时转到 NET 选项卡检查浏览器看到的标头。这会让你知道可能出了什么问题......
我用这个 -
Do you use Firebug? If yes, then go to the NET tab when your page loads & inspect what headers the browser is seeing. This will give you an idea as to what might be wrong...
I use this -
您希望浏览器缓存页面,我说得对吗?如果是这样,
Cache-Control
“private”可能是阻止浏览器缓存页面的罪魁祸首。根据 RFC-2616 第 14.9.1 节什么是可缓存,“私人”的意思是:简单来说,这意味着缓存 HTTP 代理可能不会缓存页面,但 Web 浏览器可以。但请注意,如果 Cache-Control 包含“private”,则 Web 浏览器通常不会缓存页面。
Am I correct that you want the browser to cache the page? If so,
Cache-Control
"private" is likely the culprit that is preventing the browser from caching the page. According to RFC-2616 Section 14.9.1 What is Cacheable, "private" means:Translated to plain English, this means that caching HTTP proxies may not cache the page, but the web browser can. Note, however, that web browsers often do not cache a page if
Cache-Control
includes "private".