Reputation: 2341
Hmmm okay so quick question. My server has a simple php file that is only updated lets say once a month. Now I absolutely DO NOT want the browser to check for an update until a certain period of time. Is this possible? My website specifically targets chrome users...I have an apache server and am currently using a header tag in my php:
header("Cache-Control: max-age=25200");
Which above I am pretty sure still checks for an updated page. BTW if anyone's curious the reason the browser must not check for a new page is because the webpage is HUGE. I do not want to have be re-downloaded every day.
Upvotes: 1
Views: 95
Reputation: 1603
What you have is not a bad start, but you can improve it a bit, like so:
header("Cache-Control: max-age=2592000 public");
You can add expires http header response in your .htaccess:
<IfModule mod_expires.c>
Header unset expires
ExpiresActive On
Header set Expires "Mon, 5 Aug 2013 20:00:00 GMT"
</IfModule>
If you use expires, remember to set a specific date and not a rule based in access since that doesn't work in dynamic generate content. The drawback of this, is that you have to update it from time to time.
Of course, you can also set it in your php file with a time frame of a month from the requested time, that way, you don't have to update the .htaccess and you always have a valid period.
header('Expires: '.gmdate('D, d M Y H:i:s \G\M\T', time() + 2592000));
You can add the pragma cache rule. Many modern clients don't use it, but many mobile applications and validators use it.
<FilesMatch "\.(php)$">
Header set Pragma "cache"
</FilesMatch>
Many clients also consider the etag header, so it's important to add, I use it on every project. You can do that in your .htaccess also.
FileETag All
Finally, if your site is not updated that often, the best way to improve cache and user experience, will be to have your php generate and html file and send it the client. That way, you have also the expires header working as intended and you can use compression from the server side, via apache or php.
Bye
Upvotes: 1