Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting an expiry date or a maximum age in the HTTP headers [duplicate]

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. 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.

like image 341
samayo Avatar asked Nov 21 '13 20:11

samayo


People also ask

What is Max age in HTTP header?

max-age. The max-age directive states the maximum amount of time in seconds that fetched responses are allowed to be used again (from the time when a request is made). For instance, max-age=90 indicates that an asset can be reused (remains in the browser cache) for the next 90 seconds.

What is expired HTTP header?

The Expires HTTP header contains the date/time after which the response is considered expired. Invalid expiration dates with value 0 represent a date in the past and mean that the resource is already expired.

What is cache Control HTTP header?

Cache-control is an HTTP header used to specify browser caching policies in both client requests and server responses. Policies include how a resource is cached, where it's cached and its maximum age before expiring (i.e., time to live).


1 Answers

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.

like image 167
Wayne Avatar answered Oct 01 '22 11:10

Wayne