Setting Expiration Information

Overview

You can give every page or script on the server an expiration date. The expiration date can either be in the form of an absolute date, such as January 1, 2000, or a relative date, such as 600 minutes from the time the page was first downloaded by the client browser. If a client browser requests that same page again before the expiration date and time, then the client browser uses its own cached copy.

Code Tour

This example illustrates how your script can set the expiration date for a file. The Response.Expires property is used to set the relative expiration date. The unit of measurement is minutes, so if this property is set to 10, as in the example, then the page will expire after 10 minutes.

The Response.ExpiresAbsolute property is used to specify an absolute expiration date. In this example, the page is specified to expire on January 1, 1999, at 1:30:15 P.M. Either the time or the date can be left out when assigning an expiration date.

Note   IIS sends all HTTP headers required for a given Web page or script before any HTML is sent to the client browser. Therefore, all statements and methods that modify the HTTP headers of the response, including setting the Response.Expires and Response.ExpiresAbsolute properties, must be located before the <HTML> tag in your script. If your script attempts to modify the HTTP headers after the server has begun sending HTML content back to the client browser, the script will generate an error.

Location

The VBScript and JScript versions of this script are available in the IIS samples directory, at ...\asp\interaction\Expire_VBScript.asp and ...\asp\interaction\Expire_JScript.asp.