blog posts

How to fix the Avoid CSS expressions error in gtmetrix

Another error that you may encounter when testing site speed with GT metrics is the Avoid CSS expressions error, which is related to the use of a series of JavaScript methods in CSS. Using this method is dangerous in terms of security. Of course, although such codes are used less nowadays, it cannot be said that they have been completely forgotten. Using CSS expressions, you can use a series of JavaScript methods in CSS, which are only supported in the IE browser. Among these things, we can mention changing the background color of the site over time. Now, if you have used this feature, some CSS properties will be changed dynamically. Using this feature is also dangerous, and that’s why GTmetrix recommends that you disable it if you use it.

In this tutorial from Hostfa’s knowledge base going to address how to fix the Avoid expressions error in GTmetrix. Using this tutorial, you can fix this error if you had it while testing the site with GTmetrix.

Tutorial on how to fix the Avoid CSS expressions error in GTmetrix

As mentioned, this command is for changing WordPress features dynamically. For example, let’s assume that you changed the background of the site to the desired color using the following CSS color code.

background-color: #eaa22f; 

Now, if you have used the CSS expressions function to change the background color of the site hourly and in the desired time frame, you are using such a command in CSS.

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

As you can see, two colors have been specified, which according to the order of the background color of the site will be constantly changing to these two colors, which will be done in the form of animation like this color change. Now, in order to be able to fix this error in GT Matrix, it is enough to find the file that contains CSS expressions and change the background color of the site in any section that is similar to the code above, edit it and remove this part of the code from the file. delete

If you are unable to find this file, you can search for a folder using Notepad ++ so that all the files are checked, and you can easily find the file by searching expression and deleting this part of the CSS problem code. Fix expression from GT Matrix.