Live data from Hacker News

5 Things You Should Stop Doing With jQuery

flippinawesome.org

1–6 of 6 posts

Re: 5 Things You Should Stop Doing With jQuery

#5
As far as I know, you should still use document ready. Putting javascript at the bottom does not ensure the dom is loaded before the javascript executes. Most of the time it probably is, but it's definitely not a certainty.

And not all javascript goes at the bottom, only deferable javascript belongs there. The problem caused by scripts is that they block parallel downloads. To prevent that we put as many at the bottom as is possible. But some still belong at the top if they're non-deferable; in otherwords if they should load before the dom (e.g. modernizr).

As an added fun fact: In every scenario all external CSS should load before all javascript because CSS doesn't block parallel downloads. And page display should be top priority in the load order.

Re: 5 Things You Should Stop Doing With jQuery

#6
Ironically, the .map example is actually a bit of a waste. A better function in that case is to use .filter: .map really should be used when your resultant array is the same length as the initial array, except with different elements i.e. [1,2,3,4] to [2,4,6,8], where the same function was applied to each element. For array manipulation, it is often better to use underscore.js

Edit: I just read the bit about how grep was better than your .map usage. I still think filter is better than grep in a lot of cases, esp. when you are trying to chain methods when working with an array of (jQuery) elements