Vitaly Batonov
Vitaly Batonov

Reputation: 1132

CSS expressions or javascript?

I wonder whether it makes sense to use CSS expressions if you can just use javascript.

Which would be a better or faster?

Do CSS expressions work with disabled js?

Upvotes: 2

Views: 464

Answers (3)

Spudley
Spudley

Reputation: 168685

CSS expressions are non-standard, and only available in IE.

Don't use them (except in very rare cases where they're useful to hack IE to make it do something that other browsers can do anyway).

As for performance, since expressions are themselves Javascript code, I can't imagine any scenario where they'd be quicker than plain Javascript. If anything, I'd expect it to be slower, but I don't have any firm stats on that.

For the same reason, I'd also expect it to be disabled when JS is disabled, but again I haven't got any proof of that, and I don't have time to investigate it. If it were to be run when JS was disabled, it could be considered a security risk, as disabling JS is usually done to mitigate risky scripting, and that would provide a way of circumventing it. I doubt it though, because the hackers of the world would have been all over it by now.

Upvotes: 8

brenjt
brenjt

Reputation: 16297

Javascript would definitely be faster and better. The majority of people now-a-days don't have javascript disabled so I wouldn't worry about it. If they have it disabled then not only will your site not work properly but most every other site out there. I would avoid using CSS expressions all together.

Upvotes: 3

DA.
DA.

Reputation: 40671

CSS expressions are a wart on an already ugly browser: IE. Standard advice is to avoid them whenever possible if performance is a concern.

Upvotes: 3

Related Questions