0

I should have named my question "Jquery initialization function" which includes Jquery methods and variables. Is it efficient to use following examples? Or should I use all methods in one Jquery initialization function ?

<script> 
   /* 1 */
    $(function() {
     //methods 
    });
</script>
<script>
   /* 2 */
    $(function() {
       //methods
    });
</script>
user2314737
  • 27,088
  • 20
  • 102
  • 114
osdev
  • 43
  • 7

2 Answers2

0

Using multiple initialization blocks are okay. They are perfectly valid, and don't add any overhead. In fact many of the plugins have their own $(function() {} blocks. But, there are some implications that can be caused by this, for example, subsequent blocks will not be run if one block has any error. See this answer for more details.

You can check out the answers, and follow the discussions on this thread.

And, lastly, it is always a good practice to search first for the problem.

Community
  • 1
  • 1
31piy
  • 23,323
  • 6
  • 47
  • 67
0

I wouldn't worry at this stage. Unless you are doing 100 and 100s of initialsation calls this will most likely not be your bottleneck.

Things like DOM manipulation are far more expensive.

Chris
  • 54,599
  • 30
  • 149
  • 186