浏览器不会缓存动态CSS - 响应返回200 OK而不是304 Not Modified

浏览器不会缓存动态CSS  - 响应返回200 OK而不是304 Not Modified

问题描述:

I have dynamic CSS file like this:

$Css = get_from($_u_6);



/* do stuff and other things here... */



$expires = 60*60*24; 
header("Pragma: public");
header("Cache-Control: maxage=".$expires.", must-revalidate, public");
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
header('Content-type: text/css');


echo $Css;

Headers are set correctly: http://i.imgur.com/MIH7j5U.png

But The server always responds with HTTP 200 OK (and the correct content), rather than with a HTTP 304 ( Not Modified).

How can I convince the browser and the server to cache these dynamic css files and to send 304 response?

我有这样的动态CSS文件: p>

  $ Css  = get_from($ _ u_6); 
 
 
 
 / *在这里做东西和其他东西...... * / 
 
 
 
 $ expires = 60 * 60 * 24;  
header(“Pragma:public”); 
header(“Cache-Control:maxage =”。$ expires。“,must-revalidate,public”); 
header('Expires:'。gmdate('D,d MYH)  :i:s',time()+ $ expires)。'GMT'); 
header('Content-type:text / css'); 
 
 
echo $ Css; 
  code>   pre> 
 
 

标题设置正确: http://i.imgur.com /MIH7j5U.png p>

但服务器始终以 HTTP 200 OK strong>(和正确的内容)响应,而不是使用 HTTP响应 304(未修改) strong>。 p>

如何说服浏览器和服务器缓存这些动态css文件并发送304响应? p> DIV>

The Expires: header tells the browser or cache server how long it can keep reusing the same resource without reloading it from the origin server.

If you want the browser to make a conditional request (eg. using If-Modified-Since: or If-None-Match:), you need to send a Last-Modified: and/or ETag: header, and you need to write code to test for these headers and produce the appropriate response (304 or 200).

See RFC 2616 RFC 7232 for full details.