Is there any way to delay an entire JavaScript? I mean many functions and stuff in the same time? setTimeout(func, 1000); function func() { stuff1:function(){ } stuff2:function(){ } } Code (markup): I have tried this way but my other functions are not working now... So, is there any way to delay everything without messing up the rest of the functions?
Cascade them. function func1() { /* do something */ setTimeout(func2,1000); } function func2() { /* do something else */ setTimeout(func3,1000); } function func3() { /* do a third thing*/ } setTimeout(func1,1000); Code (markup):
They are to many. Isn't there a way to just delay the loading of a javascipt file? <script src="script.js" type="text/javascript"></script> <= load this a few seconds later Or just give priority to the loading and do the rest after..
If there are 'too many' you probably have too much javascript for your page... Unless you are designing a full blown web app like google maps, you shouldn't have enough javascript to be worrying about that. But I'm the guy who considers more than 15k of javascript (uncompressed, no white space or encoding chicanery) on a website to be a complete and total /FAIL/. Just how big is your total script size?
yes you can delay this, something like this: <script id="myscript" type="text/javascript"></script> <script type="text/javascript"> // onload or domready... window.onload = function() { setTimeout(3000, function() { document.getElementById("myscript").src = 'script.js'; // load the script. }); } </script> PHP: good luck p.s. frameworks like mootools often provide methods for chaining, for example, something like: $("foobar").fade(0).chain(function() { this.fade(1); }).chain(function() { this.setStyle("border", "1px solid #000"); }); //.. and so forth, google it...