1. Page Load:
1) External SCRIPT tags have a negative impact on page performance because of their blocking
behavior. So script should be laoded load dynamic after page load.(script dom element/script defer)
2) Inline script also block the resource load, so we should move inline script to the bottom.(script defer)
2. Efficient Script:
1) Use local variables.(scope chain: local variable < array < object < global)
2) Condition:
Use the if statement when:
There are no more than two discrete values for which to test.
There are a large number of values that can be easily separated into ranges.
Use the switch statement when:
There are more than two but fewer than 10 discrete values for which to test.
There are no ranges for conditions because the values are nonlinear.
Use array lookup when:
There are more than 10 values for which to test.
The results of the conditions are single values rather than a number of actions
to be taken.
3) Loop: reference: [http://flynndang.iteye.com/blog/676977]
4) String: using + is perferred.
5) String trim:
text.replace(/^\s+/, "").replace(/\s+$/, "");
6) setTimeout delay between 50 and 100 milliseconds.
3. Image:
1)JPEG for photos, GIF for animations, and PNG for everything else. Strive for PNG8 whenever possible.(png8 < png24 < png32)
2)Don’t scale images in HTML, resize image first.
4. Domains:
1) Two domain is a good rule.
5. Iframe:
1) Iframe block the onload event.So we should void using iframe.