Super Babaca
Super Babaca

Reputation: 1655

How bad is to have a lot of $(function(){}); in code?

Thanks to an engine we have a template that puts a lot of that functions in code(for blocks with empty functionality):

    $(function(){
        // Code here
    });

Does it influence memory/speed?

Upvotes: 1

Views: 126

Answers (1)

codebox
codebox

Reputation: 20264

It will have a very slight impact on both speed (the browser will need to create a function object, which has a small overhead), and also on memory (a reference to the function will get stored by jQuery, which means the function object will be retained in memory even though it doesn't do anything).

However neither of these things should really affect the performance of your page unless you have thousands of them, a bigger problem is that it will make your code messy and harder to read!

As pointed out in the comments, it also increases the size of your page, which will increase load time.

Upvotes: 1

Related Questions