Forum Moderators: phranque

Message Too Old, No Replies

Cache-control !

An alternative to mod_headers and mod_expires

         

tomda

8:37 am on May 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I am on a shared server, therefore I have been told I can't use the mod_headers nor the mod_expires, so there is no way I can play with cache-control using Apache.

Is there any alternative ?

I just want to set an expire value for all my pictures with are many smileys and icons (jpg, gif, )... Something equivalent to

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A0
ExpiresByType image/x-icon A26611200
ExpiresByType application/x-javascript A1814400
ExpiresByType text/css A1814400
ExpiresByType image/gif A26611200
ExpiresByType image/png A26611200
ExpiresByType image/jpeg A1814400
ExpiresByType text/plain A300
ExpiresByType application/x-shockwave-flash A1814400
ExpiresByType video/x-flv A1814400
ExpiresByType application/pdf A1814400
ExpiresByType text/html A300
ExpiresByType text/php A0
</IfModule>

Can I do the same using the header() function ?

Thank you

jdMorgan

3:12 pm on May 23, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You need a new host. Using mod_headers and mod_expires is not exactly a "rare privilege" on most shared hosting services these days.

If you're really convinced that ROI on your site won't justify better hosting, you could (perhaps) use mod_rewrite to send all requests for image URLs to a script, which could output the appropriate cache-control and content-type headers, open the requested file locally, read it in, and then send the contents to the client.

This presumes that you're allowed to use mod_rewrite -- maybe not a good assumption if you can't use those other two modules.

I've got several small sites on $7.95/month shared hosting, with no such restrictions...

Jim

tomda

10:02 am on May 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks jdMorgan,

Indeed, I am considering to move to another host... But, at the same time, I am quite happy with the one I have currently, so... Don't know...

Thanks for your rewrite/redirect idea. By the way, mod_rewrite is allowed.

Yeah, I really don't know why there is a restrictions for mod_header.

Thanks

londrum

10:08 am on May 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



you can do it if you serve the images through a php script.
so instead of doing it like this,

<img src="http://www.example.com/image.gif">

you'd do something like this,

<img src="http://www.example.com/images.php?image.gif">

if you are like me and are unable to use a .htaccess file as well then it has another advantage in that you can prevent hotlinking with it.

you can sticky me for the script if you want, it's too long to put down here.

tomda

10:32 am on May 26, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks Londrum,

Yes, indeed, this could be another alternative... I will sticky you soon.

OK !
I have two alternatives...

Thanks a lot.