通过PHP设置过期标头
我们正在通过php呈现缩小的css/js,其中包含以下过期标题通过PHP设置过期标头,php,apache,Php,Apache,我们正在通过php呈现缩小的css/js,其中包含以下过期标题 header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + 3600 * 24 * 90).' GMT'); header('Cache-Control: public'); header('Last-Modified: 1407595380'); header('Content-type: text/css'); 响应标题我们被在线提到 Cache-Control publ
header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + 3600 * 24 * 90).' GMT');
header('Cache-Control: public');
header('Last-Modified: 1407595380');
header('Content-type: text/css');
响应标题我们被在线提到
Cache-Control public
Connection Keep-Alive
Content-Encoding gzip
Content-Length 3224
Content-Type text/css
Date Mon, 11 Aug 2014 14:54:55 GMT
Expires Fri, 07 Nov 2014 14:43:00 GMT
Keep-Alive timeout=5, max=100
Last-Modified 1407595380
Pragma no-cache
Server Apache/2.2.22 (Ubuntu)
但每次我刷新页面时,浏览器都会给我200个响应代码,而不是304个。浏览器并没有为php生成的缩小文件使用自己的缓存,并且在后续请求中使用了304代码的RESTCSS js
谢谢,布拉格玛:没有缓存可能会给你线索
尽管它适用于传统HTTP/1.0,但如果您使用Apache,请尝试设置
Pragma:cache
,您可以创建一个.htaccess文件,其内容为:Header unset Pragma Header set Pragma“cache”
请解释您的答案。所以不仅仅是回答问题,而是学习事情如何以及为什么会发生。
$timeToCache = 3600 * 24 * 90;
header('Expires:'.gmdate('D, d M Y H:i:s', 1407595380 + $timeToCache).' GMT');
header('Cache-Control: public');
header('Cache-Control: max-age='.$timeToCache);
header('Last-Modified: 1407595380');
header('Content-type: text/css');
header('Pragma: cache');