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.

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

报告相同问题?

悬赏问题

  • ¥30 这是哪个作者做的宝宝起名网站
  • ¥60 版本过低apk如何修改可以兼容新的安卓系统
  • ¥25 由IPR导致的DRIVER_POWER_STATE_FAILURE蓝屏
  • ¥50 有数据,怎么建立模型求影响全要素生产率的因素
  • ¥50 有数据,怎么用matlab求全要素生产率
  • ¥15 TI的insta-spin例程
  • ¥15 完成下列问题完成下列问题
  • ¥15 C#算法问题, 不知道怎么处理这个数据的转换
  • ¥15 YoloV5 第三方库的版本对照问题
  • ¥15 请完成下列相关问题!