: HTML: Images always getting reloaded from server I am finding that my web pages' images are always getting loaded from my server, even though they never change. Since these are images, not pages,
I am finding that my web pages' images are always getting loaded from my server, even though they never change. Since these are images, not pages, I can't include an expiration date for them... How can I tell browsers to avoid reloading images they already have?
Update:
In PHP I tried using this:
header ("ExpiresByType image/gif "modification plus 10 minutes"");
but this causes an internal server error.
More posts by @Sent6035632
2 Comments
Sorted by latest first Latest Oldest Best
Your header is incorrect. Here is some documentation. It should be Expires as in:
header("Expires: Thu, 30 May 2013 11:26:00 GMT");
You generally generate it in PHP like this:
header('Expires: '.date('D, d M Y H:i:s', time() + 60*10).' GMT');
There is no need to put a type because it is irrelevant. The header simply applies to the result you are serving. You can also use the max-age header instead:
header('Cache-Control: max-age=600');
ExpiresByType is an Apache directive, not PHP. Typically you would put this in a .htaccess file in the same folder as the images (or in the vhost):
ExpiresByType image/gif "modification plus 10 minutes"
You will need to have the Apache module mod_expires enabled for this to work.
Terms of Use Create Support ticket Your support tickets Stock Market News! © vmapp.org2024 All Rights reserved.