Search code examples
javascriptcssperformancecss-expressions

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?


Solution

  • 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.