I'm not sure he knows how .live works. .live doesn't wait for items to be ready and it only binds one event on to the top level document. .live waits for bubbled events and if the item bubbling the event matches this .live selector it calls back. Pretty smart if you think about it.<p>But either way he makes a great point on the document.ready if your page depends on ajax or some sort of ui styling its probably best in the header script.
Seems to me that AJAX before document-ready could get complicated once you want to actually do something with the response. Normally one would do something like this:<p><pre><code> $(document).ready(function(){
$.getJSON(my_url, function(data) {
$('<p>').text(data.some_text).appendTo('#some_container);
});
});
</code></pre>
But if we call getJSON before document-ready, the node $('#some_container') may not yet exist! Now we need some way to wait until <i>both</i> the AJAX request is complete <i>and</i> the document is ready…recommendations?<p>EDIT: Thanks for the responses, glad to know it's safer than I thought!
I know this is off topic, but there's another reason it slows you down - too many keystrokes.<p>I prefer<p>$(function(){});<p>to<p>$(document).ready(function(){});