HTTP Cache- Control

試著忘記壹切 提交于 2020-01-11 13:30:15

问题


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


回答1:


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   public, max-age=60
Content-Type    text/html; charset=utf-8



回答2:


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:

Indicates that all or part of the response message is intended for a single user and MUST NOT be cached by a shared cache. This allows an origin server to state that the specified parts of the response are intended for only one user and are not a valid response for requests by other users. A private (non-shared) cache MAY cache the response.

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".



来源:https://stackoverflow.com/questions/4360283/http-cache-control

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