Use local variables
When you call a global variable in JavaScript, the interpreter must check that:
- it exists in the current scope, in the scope above, etc.
- the variable has a value
- and more
To avoid all these checks, it is often possible to make useful variables local by transforming them into routine arguments. This process saves CPU time.
Keep repaint (appearance) and reflow (layout) to a minimum
A repaint is a change in appearance of a DOM (Document Object Model) element, while a reflow is a change/recalculation of the position of the elements in the DOM. You should avoid triggering these two operations as they are resource-expensive, especially in terms of CPU usage.