DelphiFAQ Home Search:

How I can set a time when my page expires?


comments4 comments. Current rating: 3 stars (2 votes). Leave comments and/ or rate it.


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?


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

Date: Fri, 30 Oct 1998 13:19:41 GMT
Server: Apache/1.3.3 (Unix)
Cache-Control: max-age=3600, must-revalidate
Expires: Fri, 30 Oct 1998 14:19:41 GMT
Last-Modified: Mon, 29 Jun 1998 02:28:12 GMT
ETag: "3e86-410-3596fbbc"
Content-Length: 1040
Content-Type: text/html


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.

### activate mod_expires
ExpiresActive On
### Expire .gif's 1 month from when they're accessed
### 2592000 = number of seconds in one month
ExpiresByType image/gif A2592000
### Expire everything else 1 day from when it's last modified
ExpiresDefault "modification plus 1 day"
### Apply a Cache-Control header to index.html
<Files index.html>
Header append Cache-Control "public, must-revalidate"
### Apply another header to the /images/ subdirectory
<Location /images/>
Header append Cache-Control "max-age=100"


2005-11-29, 03:50:11
anonymous from India  
2006-02-14, 12:26:14
anonymous from United Kingdom  
This text is on a zillion web pages - why not write something ORIGINAL?
2006-02-14, 13:36:26
Peter (Admin) from United States  
I personally wrote this text. Please send me urls to those zillion sites that have my text.
Or did you mean a small part of the text only?

-Peter Tiemann
2006-04-29, 21:48:18
anonymous from Australia  
was greatly helpful!



NEW: Optional: Register   Login
Email address (not necessary):

Rate as
Hide my email when showing my comment.
Please notify me once a day about new comments on this topic.
Please provide a valid email address if you select this option, or post under a registered account.

Show city and country
Show country only
Hide my location
You can mark text as 'quoted' by putting [quote] .. [/quote] around it.
Please type in the code:

Please do not post inappropriate pictures. Inappropriate pictures include pictures of minors and nudity.
The owner of this web site reserves the right to delete such material.

photo Add a picture: