nysus has asked for the wisdom of the Perl Monks concerning the following question:

I have an .shtml web page containing an SSI which calls a Perl script that generates dynamic content for part of the page. The rest of the page is regular HTML. The problem is that, on occasion (but not usually), it can take a good 5 to 10 seconds for the Perl script to finish. This means the page is blank for serveral seconds and the user is likely to think something is wrong.

I would like to provide a more user-friendly experience by posting a "Please wait while the page loads" page while the the script does its work.

How might this be accomplished?

Replies are listed 'Best First'.
Re: Generating a 'please wait' message
by Chady (Priest) on Apr 12, 2001 at 23:05 UTC

    Taking advantage of merlyn not being here... I will say that he has fixed this in one of his WebTechniques Columns :)


    He who asks will be a fool for five minutes, but he who doesn't ask will remain a fool for life.
      Do you know offhand if this can still work with the script being called from an SSI?
Re: Generating a 'please wait' message
by cLive ;-) (Prior) on Apr 12, 2001 at 23:06 UTC
    First, at the beginning of your script (after use strict; :), autoflush your output buffer:
    $|++;

    Second, I suggest your output page watches it's HTML. It's easy to create a page that displays a "This page may take 10 seconds to load, please be patient" message at the top, just as long as a TABLE tag is not waiting for the script output to finish rendering.

    For an example, go to any slashdot page with 300 comments on it. The banner ad loads quickly, the rest renders when ALL comments have loaded (ie, the TABLE they are in finishes loading).

    For longer waits, you might want to look at setting up a child process that whacks output to a static file, with auto-refresh on your 'please wait' page to check status and display when complete. (not 100% on easiest way to do this, ie "forked if I know (sic) ... oh well :)

    cLive ;-)

      I see what you are saying with "watching the HTML". Unfortunately, the HTML code generated by the script is in a table cell that runs the entire length of the page. It sounds like your second soltution may offer a possibility...and something else I need to learn!
        Why not split your HTML into two batches? It would be easy for you to add a "please wait" table to the top of your page and then the rest underneath - heck, if layout is important, why not split your existing table into two - with the first half containing the 'wait' message? I'm sure you could work it out!

        "It sounds like your second solution may offer a possibility.." - don't make life complicated if you don't need to!

        cLive ;-)

        You can often avoid using HTML tables by using Cascading Style Sheets instead. I used to try and do this a lot, and it worked great with the Internet Explorer and Opera browsers.

        The problem is that Netscape 4.x does not really support stylesheets in a meaningful way. So while IE and Opera users would see my page, Netscape 4.x users would get a blank page.

        Several years ago there were a lot of complaints about Netscape's inadequate support for CSS. I do not know whether they have fixed the problem.

        But I would say consider using CSS instead of tables to format your output, and then see whether any Netscape browser versions that you wish to support have fixed Netscape's CSS problems.

Re: Generating a 'please wait' message
by traveler (Parson) on Apr 13, 2001 at 00:29 UTC
    merlyn's column referred to above alludes to another technique: server push. This allows the server to send updates to the client browser any time it wants. With this technique you can even update images, to give the user an animated "experience" while waiting. A quick google search yielded a nice example at Netscape. And some perl code at this site.

    This approach seems to be fairly common today and is easy to do in perl. Lack of browser support is far less common today than it was in 1977...

    --traveler

      This approach seems to be fairly common today and is easy to do in perl. Lack of browser support is far less common today than it was in 1977...
      What browser was around in 1977? {grin}

      But as far as I can tell, the IE family has still not got any support for server push. So, server-push solutions work only when you know that the browser is non-standard in the same ways as Netscape browsers have been.

      -- Randal L. Schwartz, Perl hacker

Re: Generating a 'please wait' message
by one4k4 (Hermit) on Apr 13, 2001 at 19:31 UTC
    Just to provide my $.02. I had an issue with this a week or two ago. here. IE doesnt like server pushes. I posted my proposed solution to this, here. Although I havent tried it yet, it may work. We'll see. I'm sure somebody will shoot it down. :)

    _14k4 - webmaster@poorheart.com (www.poorheart.com)