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.




comments powered by Disqus