I have just finished my script, using flot and jquery. Now to my question, it is fast in opera and Firefox, but it is painfully slow in internet explorer (no surprise), so thats why I wonder if there is a way to make my script more efficient (In other words perhaps remove some of the “for loops” etc)? So if there are any code gurus out there who have some spare time to kill, please help me out, because I myself am terrible at writing efficient code 😛
Thanks so much in advance =)
It can be found
on this address
A few more tips:
It was pointed out that:
is expensive, you don’t need $ here at all, just use:
Also, using
.css(...)is a huge waste, use a class and put the CSS in an style element.You can store references like
$('#x')in closures. Again, you don’t need $, it’s far more efficient to get a reference directly to the element using document.getElementByid so that rather than:you can have:
which replaces several function calls with a single property access. The basic idea is to remove as much jQuery as you can, keep references to things rather than getting them frequently and use direct property access, not functions.
Incidentally, when I try to copy from the jsFiddle javascript region, Safari freezes. I’m not a big fan of that site.