Understanding jquery initialization

as seen when the document is loaded into the client browser,

$(function(){
some code here
});

      

...

Let's say I have two javascript files main.js

andstyle.js

main.js is for functionality and style.js for some hypothetical styling on page load. I want both files. I include them in my index.html first style.js, then main.js, both of which start with:

$(function(){
    some code here
    });

      

My question is, what is the order of execution document.ready

- is that main.js and style.js start doing something in parallel or sequentially as soon as style.js finishes what it should be doing and then main.js takes over

+3


source to share


3 answers


Well, you can have several document.ready

, but that affects the readability of the code. More has been explained here



+1


source


He is consistent. There is no parallel processing in javascript. They will be called in the order in which you included your scripts on the page.



This is a good answer too: You have some $ (document) .ready (function () {...}); section?

+4


source


Javascript won't execute parallel code by default, in order to execute code in the background you need to create webworkers . Your code is currently running in the first place.

0


source







All Articles