Still using $(document).ready in your jQuery scripts?
With the amount of jQuery tutorials being written, tweeted, and retweeted I keep seeing one common theme in nearly all of them. None of them use the jQuery shorthand to launch their scripts when their DOM is loaded.
Of course there's nothing wrong with this and it is perfectly valid, but if you are able to cut out code, that means you cut down on development. If you are familiar with jQuery then you're most likely familiar with starting your scripts like so:
$(document).ready(function() { //your code here });
Well, after actually taking the time to read through some jQuery documentation, I've discovered an easier, although more abstract way of writing this:
$(function() { // your code here });
That's all there is to it! You can get rid of (document).ready altogether. Enjoy!
UPDATE: The two methods are exactly the same, at least from what I can tell from my tests. The one exception is file size which saves 15 bytes or 16 bytes when gzipped. Special thanks to Kenneth (@ellisgl) for the test.


