在 HTTP 标头中设置到期日期或最长期限 [英] Setting an expiry date or a maximum age in the HTTP headers

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

问题描述

我刚刚完成了一个我指定的网站并将其提交给 Google 洞察

剪切和粘贴的示例

<IfModule mod_headers.c># 星期<FilesMatch ".(jpg|jpeg|png|gif|swf)$">标头集 Cache-Control "max-age=604800, public"</文件匹配></IfModule>

如果从 PHP 外壳交付材料,您可以使用 PHP 创建标头,在这种情况下,您可以参考此处概述的 HTTP 协议第 14.9 节缓存控制 http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html

我认为 .htaccess 在这两种方法中更容易.

I just finished a website that I designated 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.

解决方案

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天全站免登陆