Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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.

share|improve this question
add comment

2 Answers 2

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');
share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.