tags:

views:

1036

answers:

3

Is it bad to have multiple $(document).ready(function() {}); on your page? I have a website where I load different things at different times. I fire off those partial postback functions inside $(document).ready() but i have about 4 or 5 on the page at once. Is this a bad practice? Specifically, will it cause any performance issues?

+11  A: 

The answer is no! You can litter them as much as you want (note the word litter). They just become a queue of events that are called when the ready event is triggered.

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

Justin Van Horne
A: 

If it's on the same page I would personally put them all in the same place so that you can't be caught out by forgetting one of the things happening on load.

I doubt the performance implications are that significant though. Have you tried benchmarking the page with them all together and apart?

Garry Shutler
+2  A: 

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

Craig