Choose the right algorithm and data structure.
Refactor to simplify code.
Minimize DOM and I/O interaction.
Use local optimizations last.
When optimizing your code, start at the highest level and work your way down until the code executes fast enough. For maximum speed, work at multiple levels.