douzhi2017 2014-04-04 14:54
浏览 194
已采纳

浏览器不会缓存动态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?

  • 写回答

1条回答 默认 最新

  • doumiebiao6827 2014-04-04 15:38
    关注

    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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序