在HTTP标头中设置失效日期或最大年龄 [英] Setting an expiry date or a maximum age in the HTTP headers

查看:136
本文介绍了在HTTP标头中设置失效日期或最大年龄的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚完成了一个我设计的网站,并将其提交给Google分析
来剪切和粘贴的。

 < IfModule mod_headers.c> 
#WEEK
< FilesMatch\。(jpg | jpeg | png | gif | swf)$>
Header set Cache-Controlmax-age = 604800,public
< / IfModule>

如果从PHP shell提供资料,您可以使用PHP创建标题,到这里概述的HTTP协议14.9缓存控制 http://www.w3。 org / Protocols / rfc2616 / rfc2616-sec14.html

 <?php 
/ * This文件是一个包装,* /

header('Cache-Control:max-age = 604800');
/ *现在获取并发送图片* /
?>

我认为.htaccess更容易实现这两种方法。

I just finished a website that I desinged and submitted it to google insights http://developers.google.com/speed/pagespeed/insights/ for performance reviews, and this is the result I got.

It says, I need to set expiry date or a maximum age in the the HTTP headers, but I don't know how it is possible to set expiry date for anything other than cookies/sessions, so I have no clue what this means or how to do it.

any help would be appreciated verymuch

解决方案

Generally that is done using the .htaccess file on your host. Here is an example cut and pasted from 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>

If delivering materials from a PHP shell you could use PHP to create the header in which case you would refer to the HTTP protocal outlined here section 14.9 Cache-Control 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 */
?>

I consider the .htaccess the easier of the two methods.

这篇关于在HTTP标头中设置失效日期或最大年龄的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆