Today there was a thread on cf-talk about how to make a "Loading" or "Please Wait" style page while ColdFusion is doing something slow. Most of the answers talked about AJAX but I thought I'd show a simpler version that just used a bit of JavaScript.

First I'll create my loading message:

<p id="loading"> Please stand by while we do something. <cfoutput>#repeatString(" ", 250)#</cfoutput> </p>

Note that I gave an ID to my loading block. This will be used later. Also note the repeatString. Why do I have that? One of the "features" of IE is that it will not render any content until it gets "enough" content. I use this block of spaces simply to slap IE around and force it to render the content. My next line of code is a simple CFFLUSH:

<cfflush>

This is what tells ColdFusion to send the current output back to the browser. Now for the slow code. Obviously this will be custom for your application, but for my test I just used some Java:

<!--- slow process ---> <cfscript> go_to = createObject("java", "java.lang.Thread"); go_to.sleep(3000); //sleep time in milliseconds </cfscript>

You can find this code on the ColdFusion Cookbook entry.

Now I just need to clean up the loading text. I used this simple JavaScript:

<script language="javaScript"> loadingBlock = document.getElementById('loading'); loadingBlock.style.display='none'; </script>

And then I wrapped with a message to the user:

<p> Thanks for waiting. Here is your important information. </p>