What is an Expire Header?
An Expires Header tells the users browser how long to wait before asking for the same resource again. As an example, a css file is not going to change between requests so there is no point asking for it again. A far-future expires header has an expiration date of a week or more. On an Apache server we can use a .htaccess file to add the following command to add an expires header to our css, js, and image files telling the browser not to download these files again for a week:
Header set Cache-Control “max-age=604800, public”
But, this does not work on Google Minify. Minify is a PHP script that is combining, minifying, and echoing the contents of css and js files, but is not a CSS or JS file!
The answer lies in Minify’s config.php file.
There is a config setting that controls the maximum age of the response sent to the browser:
$min_serveOptions[‘maxAge’] = 5400;
Although the documentation does not mention it, this also controls the expires header! The above value is in seconds and works out to 90 minutes. Admit it – that’s not very far-future, is it?
I have recently become a fan of “strtotime”, so to set the expires to a week for this setting I did:
$min_serveOptions[‘maxAge’] = strtotime(“+1 week”) – time();
Et voila, the expires header for the minified css and js files has been set to a week.
The value of the expire header in Google Minify is controlled in the $min_serveOptions[‘maxAge’] setting in the config.php file. Setting it to a ‘far-future’ value will help save your bandwidth, the users’ bandwidth, and reduce the load time of your website on users’ browsers.