Page 1 of 1

How to display page before the script is over?

Posted: Thu Aug 13, 2009 7:30 am
by donald128
Hey!

My script consists of two parts.
The first part generates HTML page.
The second part loads a resourse from the net and saves it into a file.
Loading is a long operation and can take up to 10 seconds.
The first and the second parts are completely indepenent (loading has no impact on the look of the page).

At the end of the first part I call flush(), that makes page displayed instantly.

However, embedded SWF movie is not displayed at this moment.

SWF is the key element of the page and it must be displayed as fast as possible.
It is embedded in the page with SwfObject library.
And the problem is that SwfObject starts to open SWF on "onLoad" event of the page.

But "onLoad" event comes at the end of the _second_ part.
That is "onLoad" can occure in 10 seconds.
So in spite flush() call the user has to wait for 10 seconds in vain.

Is it possible to solve the task on PHP side?
Is it possible to run "loading" task (the second part) in a separate process?
Is it possible to tell the browser before the second part starts, that the page is reay and you can broadcast the "onLoad" event.

Thanks for reading this very long story.

Re: How to display page before the script is over?

Posted: Fri Aug 14, 2009 1:55 am
by robnet
Rather than using the onload event at the end of your page you could put the code in <script> tags before your flush().
So, if your code is currently 'onload='mycode()' - Add the following before flush(), but after the element it requires has been loaded:

Code: Select all

<script type="text/javascript">
 mycode();
</script>
 

Re: How to display page before the script is over?

Posted: Fri Aug 14, 2009 12:39 pm
by donald128
Thanks, robnet!
I have already found a good way to solve the problem.
I've put my SWF inside iframe.