Setting an expiry date or a maximum age in the HTT

2019-01-31 01:02发布

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. enter image description here

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

1条回答
对你真心纯属浪费
2楼-- · 2019-01-31 01:36

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.

查看更多
登录 后发表回答