【发布时间】:2013-12-06 12:25:07
【问题描述】:
我刚刚完成了一个我指定的网站并将其提交给 Google 洞察 http://developers.google.com/speed/pagespeed/insights/ 进行绩效评估,这就是我得到的结果。
它说,我需要在 HTTP 标头中设置到期日期或最长期限,但我不知道如何为 cookie/会话以外的任何内容设置到期日期。
【问题讨论】:
标签: php html http caching http-headers
我刚刚完成了一个我指定的网站并将其提交给 Google 洞察 http://developers.google.com/speed/pagespeed/insights/ 进行绩效评估,这就是我得到的结果。
它说,我需要在 HTTP 标头中设置到期日期或最长期限,但我不知道如何为 cookie/会话以外的任何内容设置到期日期。
【问题讨论】:
标签: php html http caching http-headers
通常这是使用主机上的 .htaccess 文件完成的。这是从HTTP cache headers with .htaccess剪切和粘贴的示例
<IfModule mod_headers.c>
# WEEK
<FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
Header set Cache-Control "max-age=604800, public"
</FilesMatch>
</IfModule>
如果从 PHP 外壳交付材料,您可以使用 PHP 创建标头,在这种情况下,您可以参考此处概述的 HTTP 协议第 14.9 节缓存控制http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html
<?php
/* This file is a wrapper, */
header( 'Cache-Control: max-age=604800' );
/* now get and send images */
?>
我认为 .htaccess 在这两种方法中更容易。
【讨论】: