View Single Post
Old 02-29-2008, 02:05 AM   #5 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

The Expires header is one that you should be using (and probably are without knowing it) for anything which isn't 100% dynamic content. It's just another normal header (like Content-Type, Location, etc.). The purpose is simply to tell the client (browser) that after the expiry time, it must ask the server for a fresh copy of the item. The value of the header must be a date like Fri, 29 Feb 2008 01:52:00 GMT.

If the server doesn't send an Expires header, or one which is really short, then your browser will keep asking to see if it needs to re-download the content (or worse, cache the content however long it feels like) whenever you try to view the page/image/whatever. If the server says, for image.jpg, "Hey this image expires in a week" and you view the image 100 times a day (it's a photo of your new pet, or something) that's lots less downloads than if your browser just grabbed the file every time.

Other helpful headers to look into are Last-Modified and If-Modified-Since, for a start, which can further help with caching (and reducing time and effort travelling to and from the server) in a more flexible way than Expires.

P.S. I'm sure there was an article or two somewhere recently about this, aimed at using these headers specifically with PHP, but I can't remember where it was.
Salathe is offline  
Reply With Quote
The Following 2 Users Say Thank You to Salathe For This Useful Post:
Alan @ CIT (02-29-2008), Runar (11-07-2008)