What should be and what should be from jQuery.ready ()?

What should be and what should be from jQuery.ready ()?

From a performance point of view, I read somewhere that placing all the codes enclosed inside jQuery.ready() is not an efficient way.

Then my question is: what should be and what can be indifferent without problems (I think delegates could be left outside, but this is a quick guess)?

thanks

+4
source share
3 answers

For maximum performance, put js before closing the body tag. This way you can completely eliminate jquery. The user interface loads quickly because it is not blocked by loadable scripts and when js is parsed and called, you can be sure that the elements in the dom above are ready to be manipulated.

+3
source

jQuery.ready () is called after the page loads. See the first sentence in jQuery.ready () . If you want events to fire before the page has been done, loading jQuery.ready () would not be the appropriate way.

0
source

You must save functions like

 fnc = function() { ... }; 

or any other declaration. Because if you write all this down, this code will only start executing when the entire DOM is loaded. Otherwise, it starts executing immediately after loading it. The jQuery wrapper should only be present when your javascript requires the DOM to load.

 var blah = function() { //... }; $(function() { //same as jQuery(document).ready or $(document).ready blah(); }); 
0
source

All Articles