wilson1000
asked on
Add Expires Headers - PHP
Hi Experts,
Can you please tell me how to efficiently add expires headers to html elements please? gtmetrix.com is saying that expires headers are normally used with images but should also be used with all page componants including scripts, css and flash.
How can this be done? I'm using PHP if that helps.
Thank you
Can you please tell me how to efficiently add expires headers to html elements please? gtmetrix.com is saying that expires headers are normally used with images but should also be used with all page componants including scripts, css and flash.
How can this be done? I'm using PHP if that helps.
Thank you
You would normally add such headers by either configuring the webserver (for example using a .htaccess) or by serving the page components through PHP. The first method is preferred, as it doesn't require PHP to be loaded for every component. Have a look at http://www.askapache.com/htaccess/apache-speed-expires.html for an example using .htaccess.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi, thanks gentleman.
I have tried the PHP header() function but this is returning no results within the live web test so I'll pass this over to our backend developer for changes to server config.
I'll return soon!
Thanks again
I have tried the PHP header() function but this is returning no results within the live web test so I'll pass this over to our backend developer for changes to server config.
I'll return soon!
Thanks again
ASKER
Hi, quick question...
@ svgmuc: How do we format the code for server config? I take it we remove the quotes ""?
@ svgmuc: How do we format the code for server config? I take it we remove the quotes ""?
ASKER
Hey don't worry... I followed your link and found the resource at apache.
I use this codes on my development :
<?php
header("Expires: Thu, 17 May 2001 10:17:17 GMT"); // Date in the past
header("Last-Modified: " . gmdate("D, d M Y H:i:s") . " GMT"); // always modified
header("Cache-Control: no-cache, must-revalidate"); // HTTP/1.1
header("Pragma: no-cache");
ob_start();
?>
ASKER
I see what you're saying however, I need to instruct the user agent to cache a vast majority of files that we distribute with our page.
Your expires header looks to be initializing no cache at all.
As I said before, I've used the code below to no avail and would like the server to take care of this... running test now so will get back in a short time...
Your expires header looks to be initializing no cache at all.
As I said before, I've used the code below to no avail and would like the server to take care of this... running test now so will get back in a short time...
$expires = 60*60*24*14;
header("Pragma: public");
header("Cache-Control: maxage=".$expires);
header('Expires: ' . gmdate('D, d M Y H:i:s', time()+$expires) . ' GMT');
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Thank you,
I was only going to award points to @svgmuc for his direction as this is what I needed however, Ray offered a great solution to cover required downloads.
I was only going to award points to @svgmuc for his direction as this is what I needed however, Ray offered a great solution to cover required downloads.