I have a page where php displays a fairly large div that has a lot of components inside it. JS to process this div starts almost instantly, but there are time issues associated with loading bigDiv and a script that process it.
So, I applied such code to process it on ready ()
var bigDiv = $(document).find('#bigDiv'); bigDiv.ready(function{
Now my question is: if bigDiv takes a long time, how long does the ready() function work? What if bigDiv is not displayed at all?
So, to avoid waiting for the script, I applied a timeout,
So I chose a different approach similar to this:
var waitTimer = 0; var lodTmout = 2000; function chkDataLod(){ var bigDiv = $pH(document).find('#bigDiv'); if(bigDiv.length > 0){//find if bigDiv has content bigDiv.ready(function(){//wait for bigDiv to load it contents completely //some code here }); }else{ //chk for bigDiv after every 500 msec for 2000 msec if(waitTimer === lodTmout){ return false; }else{ waitTimer += 500; setTimeout('chkDataLod();',500); } } }; function _init(){ chkDataLod(); } _init();
Initially, I tried to see if bigDiv content was longer than zero. The problem arose when the "incomplete download" of bigDiv was displayed. So I added the .ready() function again. I have some animation features on this big Div that I don't want to run until it is fully loaded.
This bigDiv loaded from the CDN, so the loading time changes. Once it took almost 5 seconds to load. Seeing my own approach, I know that he has problems. I am using setTimeout and ready, both. But I'm not sure I'm ready to wait. I tried to see its documentation, but could not find it clearly.
How can I solve this problem for this situation?
source share