HTTP Cache- Control
I am struggling with thi开发者_StackOverflow社区s - 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
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
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".
精彩评论