Outside the Cube
About this site
Links to us
Outside the Cube
Male Dating Scammers,
Generated 8:02:10 on Jun 4, 2020
How I can set a time when my page expires?
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
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
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
### 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
Header append Cache-Control "public, must-revalidate"
### Apply another header to the /images/ subdirectory
Header append Cache-Control "max-age=100"
|Most recent comments