Notice: With the launch of Adobe Cookbooks, this site will no longer be accepting new entries or posting new content. Thanks to everyone who submitted content!

How can I prevent a browser from caching my page?

By default, browsers will try to cache the contents of a page. Because of their dynamic nature, most ColdFusion pages will automatically force a browser to reload them on each visit. However, you may still want to keep the contents of a more static page (for security or other reasons) from being cached. In these types of situations, you can use the <cfheader> tag or the html <meta> tag.

Place the following three <cfheader> tags at the top of a page to keep it from being cached:

<cfheader name="cache-control" value="no-cache, no-store, must-revalidate">
<cfheader name="pragma" value="no-cache">
<cfheader name="expires" value="#getHttpTimeString(now())#">

You can also use set a meta tag for content expiration

<meta http-equiv="expires" content="<cfoutput>#getHttpTimeString(now())#</cfoutput>">


This question was written by Jeremy Petersen.
It was last updated on February 7, 2006 at 10:50:01 AM EST.

CFML Referenced

Now()
<cfheader>
<cfoutput>

Categories

Caching

Comments

Comment made by Simon Bailey on February 13, 2007 at 3:31 PM
Hi, I was wondering on how I could impliment the above into a cfc to save repeating the code in each individual cfm page?

Ta Simon