Outside the Cube (8748)
Web publishing (65)
about DelphiFAQ (14)
perl CGI (3)
Web Hosting (8)
New related comments
Number of comments in the last 48 hours
Getting started with CSS
How I can set a time when my page expires?
4 comments. Current rating: (2 votes). Leave comments and/ or rate it.
Question:I need to supply an expiration date for my web page so that it does not get cached beyond that date. How should I do that?
Answer:Often you will see the advice to use a meta tag in the <HEAD> section of the page. While meta tags are easy to use, they are ineffective. That's because they're usually only honored by browser caches (which actually read the HTML), not proxy caches (which almost never read the HTML in the document).
The more effective place to put this information is in the actual HTTP headers (which are not displayed in the browser, not even with View-Source). These headers give you a lot of control over how both browser caches and proxies handle your objects. It is a bit more difficult to set the HTTP headers since they're usually generated by the web server.
In your case, you may want to add a Cache-Control or an Expires header. A typical example for such a header (containing both) would be:
HTTP/1.1 200 OK
How do you get those headers to be delivered with your page?
If your content is generated by perl or another language, then the answer is easy. Simply add a print statement putting out the header.
For static documents under Apache, you can configure your headers in the .htaccess file. If you have an .htaccess file in your (www) root directory, it will affect all directories below. Ideally you'll have ssh access to your web server to perform this, but just plain ftp access will do too. The .htaccess file allows you to override Apache's defaults as they are set up in the configuration file.
Here's an example .htaccess file that demonstrates the use of some headers. As you see this .htaccess file references the Apache module mod_expires. You need to have this module installed; if not complain to your administrator or install it yourself.