don't use:
with
try-catch in a loop
globals
for in
Slide 17
Slide 17 text
speeding up code
Cache out of scope variables
Cache array.length
String-building
Cache calculations
someFunction = someObject.someFunction;
for (...) {
someFunction(...);
}
Slide 18
Slide 18 text
speeding up code
Cache out of scope variables
Cache array.length
String-building
Cache calculations
for (var i = 0, l = arr.length; i < l; i++) {
...
}
Slide 19
Slide 19 text
speeding up code
Cache out of scope variables
Cache array.length
String-building
Cache calculations
var stringBuilder = [];
for (...) {
stringBuilder.push('a');
}
var string = stringBuilder.join('');
Slide 20
Slide 20 text
speeding up code
Cache out of scope variables
Cache array.length
String-building
Cache calculations
Slide 21
Slide 21 text
working with the dom
Use CSS
Keep it small (virtual rendering)
Minimise reflows/repaints
position: absolute;
left: 50%;
margin-left: -200px;
width: 400px;
Slide 22
Slide 22 text
Minimising reflows
innerHTML/$.html over creating nodes
Batch setting styles
Stay low in the DOM tree
Detach/hide nodes
Slide 23
Slide 23 text
Minimising reflows
Cache node properties
Position: fixed/absolute for animations
Avoid tables for layout