IE6 performance with CSS expressions

一个人想着一个人 提交于 2019-12-03 16:38:17
Luca Matteis

https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-7-avoid-css-expressions-7202.html

Turns out you might want to avoid using these, they are dangerous.

Expressions are re-evaluated on many page events, which has the potential to slow down entire page performance when used too liberally. (And yet still, they can't respond to all events that might cause them to need re-evaluating.)

MS have admitted expression() was a mistake, and are removing it from future browsers.

There are generally better individual JavaScript workarounds for IE6's various CSS shortcomings.

It is rather sad that so many companies are still sticking with the dire IE6. Maybe if you deliver the project late they'll have upgraded by then!

It is possible to make IE expressions perform optimally, not only to avoid things like continuous re-evaluation, but to also hook your desired style to IE-specific classnames, therefore making your IE-Specific CSS easier to maintain (as the expressions themselves are disgusting):

input
{
    1:expression(this.executedExpressions ? void 0 : this.className += (this.type == 'text' ? ' ie-text' : ''));
    2:expression(this.executedExpressions = true);
}

input.ie-text
{
    background-color:silver;
}

If you're going to use IE expressions at all, this is the best way. (I really ought to write a thorough article about it).

Unfortunately CSS expressions are very poor performance wise, as the result is calculated constantly, all the time the page is loaded, not just when the page is first loaded. If you have to use expressions then you'd be better off use using standard JavaScript with an onLoad event.

See this article for more info: http://www.robertnyman.com/2007/11/13/stop-using-poor-performance-css-expressions-use-javascript-instead/

I'd suggest you to switch to any JS Framework which supports CSS Selectors so you can emulate the behaiviour of CSS expressions

you can test JS Frameworks performance if you open this URL on IE6

http://slicktest.perrohunter.com

cheers

Yes, expressions are realy slow in IE period. Find ways to avoid them.

I haven´t tried it myself, but IE7-js looks promising. It claims to make IE6 compatible with IE7

Edit: By the way, to just add some styles for IE6, you can also use

<!--[if lt IE 7]>
<link rel="stylesheet" type="text/css" media="screen"  href="ie6styles.css" />
<![endif]-->

And you can always use jquery to set css properties dynamically in all browsers including IE6.

If you do have to use them, the techniques found at One-time execution of IE CSS expressions will help with the performance (but not security) issues.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!