954,585 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

how to add expires header to images?

How can i add expires header to images?
i used the following in css file and php respectively

<?php
-----------CSS------------------------------------------------------
   ob_start ("ob_gzhandler");
   header ("content-type: text/css; charset: UTF-8");
   header ("cache-control: must-revalidate");
   $offset = 48 * 60 * 60;
   $expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
   header ($expire);
?>
----------PHP------------------------------------------------------
<?php
if (substr_count($_SERVER['HTTP_ACCEPT_ENCODING'], 'gzip'))
	ob_start("ob_gzhandler");
else
	ob_start();
header ("content-type: text/html; charset: UTF-8");
header ("cache-control: must-revalidate");
echo  $offset = 48 * 60 * 60;
$expire = "expires: " . gmdate ("D, d M Y H:i:s", time() + $offset) . " GMT";
header ($expire);
?>


Both are working but it does not applies to the images used in css files. They need to be specified separately.
How?
This is my problem can any one help me please...
Also if u can please tell me how to specify Etags?

I also tried in another method using .htaccess

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType image/gif A2592000
ExpiresByType image/jpg A2592000
ExpiresByType image/png A2592000
ExpiresByType application/x-javascript A2592000
ExpiresByType text/css A2592000
ExpiresByType image/x-icon A2592000
</IfModule>

i think this is working but not working for icon files
i also don know what this means "A2592000"
how can i set my own time for as expire header?Thanks in adavance.

danishbacker
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 10
Solved Threads: 7
 

Problem solved. The second method is working.
Using .htaccess

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 days" 
ExpiresByType image/gif "access plus 60 days"
ExpiresByType image/jpg "access plus 60 days"
ExpiresByType image/png "access plus 60 days" 
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType text/css "access plus 60 days"
ExpiresByType image/x-icon "access plus 360 days"
</IfModule>


Also i got the meaning of A2592000 = 720hours = 30days
the numbers after A is the time to expire time (in seconds)
ie A3600 is 1 hour

Thank you all.

danishbacker
Junior Poster in Training
97 posts since Apr 2008
Reputation Points: 10
Solved Threads: 7
 

Thanks a lot man!
I registered just to say THANKS to you!

Cheers!

Problem solved. The second method is working. Using .htaccess

<IfModule mod_expires.c>
ExpiresActive On
ExpiresByType text/html "access plus 2 days" 
ExpiresByType image/gif "access plus 60 days"
ExpiresByType image/jpg "access plus 60 days"
ExpiresByType image/png "access plus 60 days" 
ExpiresByType application/x-javascript "access plus 60 days"
ExpiresByType text/css "access plus 60 days"
ExpiresByType image/x-icon "access plus 360 days"
</IfModule>

Also i got the meaning of A2592000 = 720hours = 30days the numbers after A is the time to expire time (in seconds) ie A3600 is 1 hour

Thank you all.

bbrosg
Newbie Poster
1 post since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You