1. Learn the techniques of asynchronous programming
2. Pass local variables
3. Keep code small and light
4. Avoid unwanted loops
5. Cache objects to increase performance
It’s common practice in programming to have a script repeatedly access certain objects. For example, in the following example, notice how the browser must dynamically look up the object, “document.images” two times for each loop – once to see if i<document.images and the second time to change the images src. If you have 10 images then this amounts to 20 calls to the images object.
An alternative method is to “cache your object”; this means storing a repeatedly accessed object inside a user defined variable, and using that variable instead in subsequent references to the object. The performance improvement can be significant. In the following example, the number of times document.images is referenced is half of the previous version, which significantly reduces the load on the browser.
It is common practice for scripts to repeatedly access a certain object. By storing a repeated access object inside a user defined variable, as well as using a variable in subsequent references to that object, performance improvement can be achieved immediately.