admin管理员组文章数量:1287136
It is well known that the Internet Explorer Javascript Engines are way behind in terms of performance, in particular IE 8 and older, when pared to Chrome, Safari (Webkit) or Firefox (Mozilla).
When developing a web application with significant javascript functionality, IE performs much worst than the others.
Are there any practices that could help improve your javascript code so the divide between the good performers (non-IE) and the bad performer (IE) is not that wide?
It is well known that the Internet Explorer Javascript Engines are way behind in terms of performance, in particular IE 8 and older, when pared to Chrome, Safari (Webkit) or Firefox (Mozilla).
When developing a web application with significant javascript functionality, IE performs much worst than the others.
Are there any practices that could help improve your javascript code so the divide between the good performers (non-IE) and the bad performer (IE) is not that wide?
Share Improve this question asked Jan 13, 2012 at 4:20 agarcianagarcian 3,9633 gold badges34 silver badges55 bronze badges 2- 1 possible duplicate of How can I optimize for IE? – Mike Samuel Commented Jan 13, 2012 at 5:26
- The two top-rated answers of that question are pretty much the same advice that's applicable here, too. – Joey Commented Mar 27, 2012 at 6:12
4 Answers
Reset to default 2Another couple of mon 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 mon 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./kb/982891
a. One way to increase your performance in older versions of IE would be to use RAW JavaScript to create DOM elements instead of jQuery.
example -
(function () {
var rosterContainer = document.getElementByID("roster");
var memberContainer = document.createElement("div");
$(memberContainer).addClass("one_fourth alpha hentry")
.attr("id", mName.replace(/\s+/g," "))
.appendTo($(rosterContainer));
})();
b. You can also re-engineer your user experience (UX) for IE browsers.
Example - my site uses heavy JS/jquery plugins to load large backgrounds and show them as a slide show with alpha tweens. But for my IE users, I don't load the JS or the plugin or the background images - i just show a static titled bg.
you can use loaders like yepnope.js to load optimized JS for IE
c. Make sure your site's UI is fully functional w/o JavaScript. This is always a good place to start.
本文标签: performanceJavascript optimizations for Internet ExplorerStack Overflow
版权声明:本文标题:performance - Javascript optimizations for Internet Explorer - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741299878a2371032.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论