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.

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

报告相同问题?

悬赏问题

  • ¥20 Linux上make出现错误不知道怎么解决
  • ¥15 prism提示我reinstall prism 如何解决
  • ¥15 asp.core 权限控制怎么做,需要控制到每个方法
  • ¥20 while循环中OLED显示中断中的数据不正确
  • ¥15 这个视频里的stm32f4代码是怎么写的
  • ¥15 JNA调用DLL报堆栈溢出错误(0xC00000FD)
  • ¥15 请教SGeMs软件的使用
  • ¥15 自己用vb.net编写了一个dll文件,如何只给授权的用户使用这个dll文件进行打包编译,未授权用户不能进行打包编译操作?
  • ¥50 深度学习运行代码直接中断
  • ¥20 需要完整的共散射点成像代码