views:

65

answers:

2

I have a feeling I'm missing something obvious, but...

All my neat jQuery functions are being forced to wait by a particularly slow-moving javascript api call from within the body of the page. I'd like to have the jQuery run first, and then the api when that's done. Is there a standard way of imposing the order?

+4  A: 

easy workaround, call your api within a setTimeout statement.

Example:

$(document).ready(function(){
     // beautiful jQuery code here
     setTimeout(function(){
        // terribly slow code here
     }, 100);
});

It is in general a good idea to use setTimeout on heavy code/DOM manipulation. It will avoid the browser from "freezing".

jAndy
+1  A: 

Well if you just want the jquery before the javascript, do this:

function japi(){
   japi.dosomething();
   //Your api part here
}

$("#test").html("something");
//Lots of jquery here
japi();
Neb