Live data from Hacker News

JQuery Performance Tips Cheat Sheet

dumitruglavan.com

21–24 of 24 posts

Re: JQuery Performance Tips Cheat Sheet

#21

As for the recommendation to use his custom testing/benchmarking library: don't! It's based off an old version of jQuery, it duplicates functionality of better-maintained libraries, and it opens up a new vector for arbitrary code evaluation/execution ($.bm);

I would discount any performance/benchmarking discussions unless it uses jsperf, benchmarkjs or a similar suite.

Re: JQuery Performance Tips Cheat Sheet

#22
post #6

Man... this is full of crazy talk: For better performance you can use direct functions like $.ajax() than $.get(), $.getJSON(), $.post() because the last ones are shortcuts that call the $.ajax() function. I've never written an app where the overhead of $.getJSON has been any kind of bottleneck. Don’t forget about using .data() function to store stuff for your elements How is this a performance tip? Sometimes it’s fa…

Some of these exemplify "premature optimization" and will clutter code with no discernible benefit. I remember some days ago, in the days of PHP, there were heated debates about whether or not using single or double quotes for strings makes code faster.

As with most development, use good practices. But then at the end of the day, profile your application to find the actual bottlenecks.

Re: JQuery Performance Tips Cheat Sheet

#23
post #2

The #id selector performance tip is definitely true, but in single-page interface you never know which DOM elements may be floating around on a page, which would go against the one id per page principle.

You can't have two elements with the same id. Well, you can, but it's not valid.

Re: JQuery Performance Tips Cheat Sheet

#24
post #5

It would be nice to see measurements on how much less time and memory the more performant techniques take compared to their less performant counterparts in realistic scenarios. Doing so might indicate a better ranking of the tips given. For example, the DOM insertion tip -- which drastically improves performance over the naive implementation -- is tip 9, and is probably far more useful than tips 4 (Optimize selectors…

You could always set up some tests using jsperf.com. I don't believe it does memory usage though.

Seems like people are testing the sort of things measured in this article at the moment too eg.:

http://jsperf.com/jquery-multiple-id-perf

Post reply on HN