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.

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.

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.

real big thanks here too ...you da man Danish Backer. Been looking for a cache solution for my mobile websites.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.