Avoid CSS expressions on html page

CSS expressions are a powerful (and dangerous) way to set CSS properties dynamically

They are supported by Internet Explorer, since version 5. For example, the background color can be alternated every hour using CSS expressions.

background-color: expression ((new Date ()). getHours ()% 2? "# B8D4FF": "# F08A00");

As shown here, the expression method accepts a JavaScript expression. The CSS property is set to the result of the evaluation of the JavaScript expression. The expression method is ignored by other browsers, so it is useful for adjusting the Internet Explorer properties necessary to create a consistent experience across browsers.

The problem with expressions that are evaluated more frequently than most people expect. They are not only evaluated when the page is rendered and resized, but also when the page is navigated and even when the user moves the mouse cursor over it. Adding a counter to the CSS expression allows us to monitor when and how a CSS expression is evaluated. By moving the mouse cursor around the page you can easily generate more than 10,000 evaluations.

One way to reduce the number of times your CSS expressions are evaluated is to use expressions only once, where the first time the expression is evaluated the property style is set to an explicit value, which replaces the CSS expression . If the property style is to be dynamic throughout the life of the page, an alternative can be focused with events instead of CSS expressions. If using CSS expressions is irreversible, remember that they can be evaluated thousands of times and could affect the performance of your page.

Date update on 2020-11-13. Date published on 2020-11-13. Category: Computer class Author: Oscar olg Fuente: tecnologia