我们通过 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 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生成的缩小文件,其余css js在后续请求中具有304代码。
谢谢
$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');
Pragma: no-cache
可能会给你线索。
虽然它适用于旧版 HTTP/1.0,但请尝试设置Pragma: cache
。