为Internet Explorer的Javascript优化 [英] Javascript optimizations for Internet Explorer

查看:111
本文介绍了为Internet Explorer的Javascript优化的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

众所周知,互联网浏览器的JavaScript引擎是远远落后在性能方面,特别是IE 8及以上,相对于浏览器,Safari浏览器(WebKit的)或Firefox(Mozilla的)。

It is well known that the Internet Explorer Javascript Engines are way behind in terms of performance, in particular IE 8 and older, when compared to Chrome, Safari (Webkit) or Firefox (Mozilla).

在开发具有显著JavaScript功能的Web应用程序,IE浏览器的性能比别人多的最差的。

When developing a web application with significant javascript functionality, IE performs much worst than the others.

有没有可以帮助提高你的JavaScript code所以表现良好(非IE)和坏的表演者(IE)之间的鸿沟不是宽?

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?

推荐答案

另一对夫妇共同的解决方案:

Another couple of common solutions:

缓存常用的DOM节点,不要再重新计算他​​们在相同的功能。例如。而不是

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

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

使用

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

缓存频繁使用的对象,从外部范围即可。例如。而不是

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

使用

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

这将收到和污染减量后code尺寸也积极的影响。

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

这篇关于为Internet Explorer的Javascript优化的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆