JQuery - it's bad to have multiple $ (document) .ready (function () {});

Is it bad to have a few $(document).ready(function() {}); on your page $(document).ready(function() {}); ? I have a website where I upload different things at different times. I run partial postback functions inside $(document).ready() , but I have about 4 or 5 on the page right away. Is this a bad practice? In particular, will this cause any performance issues?

+44
jquery ajax
Jul 18 '09 at 18:35
source share
4 answers

This answer is no longer relevant. See Other Posts below for more current jQuery $ .ready () effects. This post is older than 3 years.

See: http://jsperf.com/docready/11

The answer is no! You can clog them as much as you want (pay attention to the broken garbage). They simply become a queue of events that trigger when a ready event fires.

http://www.learningjquery.com/2006/09/multiple-document-ready

+32
Jul 18 '09 at 18:39
source share
— -

The answer is actually “Yes, it is holding back performance”:

http://jsperf.com/docready/3

+11
Nov 27 '11 at 7:52
source share

No, you will have as much as you want. A shorter, much more elegant way to do this is $(function(){}) though.

+3
Jul 18 '09 at 18:45
source share

If on the same page I personally put them all in one place so that you don’t get caught, forgetting what happens when loading.

I doubt the performance implications are so significant. Have you tried to match the page with them all together and apart?

+1
Jul 18 '09 at 18:40
source share



All Articles