Javascript optimizations for Internet Explorer Javascript optimizations for Internet Explorer google-chrome google-chrome

Javascript optimizations for Internet Explorer


Another couple of common solutions:

Cache frequently used DOM nodes, do not recalculate them in the same function again. E.g. instead of

$(id).parentNode.something();$(id).parentNode.somethingOther();

use

var e = $(id).parentNode;e.something();e.somethingOther();

Cache frequently used objects from outer scope. E.g. instead of

if (this.options.type == 'a') {    // ...} else if (this.options.type == 'b') {    // ...}

use

var type = this.options.type;if (type == 'a') {    // ...} else if (type == 'b') {    // ...}

This will have also positive impact on code size before and after minifying.


One common way to optimize performance is caching the 'max' value in for loops.

So, let's say you have to iterate through an array called sampleArray. You could optimize the below statement:

var sampleArray = [3, 10, 12, 5, 9];for(var i = 0; i < sampleArray.length; i++){   var currentElement = sampleArray[i];  // so something wit element}

by changing it to be:

for(var i = 0, max = sampleArray.length; i < max; i++){       var currentElement = sampleArray[i];      // so something wit element}

This has shown to show a pretty big performance increase in all browsers. In particular, IE7 has proven to get a 190 times increase in performance using this pattern (from High Performance Javascript)


I think reasonable solution for it is Google Chrome Frame
This just allow use Chrome Frame in IE and don't use it in non-IE browsers.

JavaScript performance and development tools for IE:
Microsoft Support: Internet Explorer Performance Article - http://support.microsoft.com/kb/982891