Setting an expiry date or a maximum age in the HTTP headers(在 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 标头中设置到期日期或最长期限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:在 HTTP 标头中设置到期日期或最长期限
基础教程推荐
- 在PHP中根据W3C规范Unicode 2022-01-01
- Cron Jobs 调用带有变量的 PHP 脚本 2022-01-01
- 如何替换eregi() 2022-01-01
- PHP 类:全局变量作为类中的属性 2021-01-01
- 学说 dbal querybuilder 作为准备好的语句 2022-01-01
- 有什么方法可以用编码 UTF-8 而不是 Unicode 返回 PHP`json_encode`? 2021-01-01
- PHP PDO MySQL 查询 LIKE ->多个关键词 2021-01-01
- 如何在 Laravel 中使用 React Router? 2022-01-01
- 如何在 Laravel 5.3 注册中添加动态下拉列表列? 2021-01-01
- YouTube API v3 点赞视频,但计数器不增加 2022-01-01
