I’ve been looking through a lot of Javascript Optimizing and most of them talk about string concatenation and a few other big ones found here, but I figured there had to be more details that you can optimize for when speed is critical and the processing of those pieces of code is very high.
Say you run this code for some reason: (unlikely, I know, but bear with me)
for( var i = 0; i < 100000000000; i++ ) {
//Do stuff
}
And there’s no way of getting around having a loop that big… You’re going to want to make sure that all the stuff you’re doing in that loop is optimized to the point that you can’t optimize it anymore… or your website will hang.
Edit: I’m not necessarily talking about a loop, what about a function that’s repeatedly called such as onmousemove? Although in most cases we shouldn’t need to use onmousemove, there are some cases that do.
This questions is for those cases.
Using JQuery as our JS library
So what I would like is tips for optimizing, but only the more uncommon ones
– ie. Speed differences between switch or if-else
If you’d like to see the more common ones, you can find them here:
You can speed up this mofo thus:
Reverses the loop and checks only for
instead of
Performance gain of 50% in most browsers
Saw this in a great Google Code talk @ http://www.youtube.com/watch?v=mHtdZgou0qU
The talk contains some other great tricks.
Good luck!