How can I display a message on a long-running page?

By default, ColdFusion will not return any HTML until the entire page has rendered. For a long-running page, this may make the user think nothing is happening, resulting in the user hitting reload multiple times.

ColdFusion provides a tag that will flush out the current data to the screen: <cfflush>. For example:

This is a slow page, please stand by...
<cfloop index="x" from="1" to="999999">
	<cfset doNothing = x*2/3>
I'm finally done.

In this example, the user will see the "please stand by" warning immediately. After the page has processed they will then see the final message. A few warnings about <cfflush>. When used - the following tags and functions may no longer be used: <cfcontent>, <cfcookie>, <cfform>, <cfheader>, <cfhtmlhead>, <cflocation>, and SetLocale(). Also, some browsers, like the wonderful Internet Explorer, will ignore your text unless you have "enough" text. If you see nothing in Internet Explorer, you can simply pad your output by adding: repeatString(" ", 100). This fools the browser into thinking enough text has been sent to render.

This question was written by Raymond Camden
It was last updated on February 23, 2006.


Display and Layout


comments powered by Disqus