Mobile app version of vmapp.org
Login or Join
Sent6035632

: 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,

@Sent6035632

Posted in: #Html #Http #Images #Php

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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Sent6035632

2 Comments

Sorted by latest first Latest Oldest Best

 

@Shelley277

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');

10% popularity Vote Up Vote Down


 

@Cooney921

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.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme