Optimize CSS

It does not matter if you are an experienced developer or if you are building your first website. It is very easy to end up with a large bloated CSS file. There are several reasons that you might end up with a bloated CSS file. You might have added too many unnecessary elements to the website or you might have built on some one else’s work that contains no longer used code. Regardless of the reason you should try to unbloat the file as much as possible.

Why is a bloated CSS file a problem

optimizeA bloated CSS file takes longer time to load than a smaller file. A bloated file can also cause a slower computer system to need more time to render the website. This should normally not be noticeable but can effect a low number of systems and you should always build a website that works as well as possible on any users system.

Slower load times and slower rending times can cause the website to rank lower in search engines than it otherwise would. It can cause users to decide to not visit your website. Studies shows that half of all users will press the back button if your website takes more than 3 seconds to load.

It is not unusual that the CSS file is the largest single file that needs to be loaded before the website renders and it will therefor be the CSS file that blocks the page from loading.

Is a large CSS file a bloated CSS file?

No. A large CSS file is not the same thing as a bloated CSS file. A bloated CSS files contains rules and code that does not need to be there. Either because it is not used on the website or because it is used to add elements that do not add to the customer experience.

  • A large file can be lean if it only contains necessary code.
  • A small file can be bloated if it contains unnecessary rules.

Bloat is very common

A very large percentage of all CSS files contains bloat and if you are using a premium or free theme then you can be certain that the theme contains bloat. This is due to the fact that the developer developed a theme that is supposed to work well on all websites that uses it. Odds are that you do not use all the functions in the theme. The theme is likely to haveCSS rules for the feature you are not using. These rules are to be considered bloat. A lot of themes contains several different color schemes. Most of them combine all of the rules for all of the color schemes in the same CSS meaning that for every used rules there are several unused rules for the same element in another color schemes. If you use a theme like this then it is common that the CSS file is 75% bloat and you can make your website a lot leaner by removing the unused rules

Finding unnecessary CSS code

finding bloated filesThere are many ways to remove the bloat and optimize your CSS file. There are tools that do it automatically and there are tools that show you what to remove manually. A tool that allows yo do it manual is to be recommended. They are a little harder to use but they give you better control and produce a better result It is common that automatic tools break the website by removing rules that are need by mistake.

I recommend using DUST-ME to scan for unused rules. DUST-ME is an extension for Firefox and is very reliable. There are several other options out there if you prefer to use another solution.

Removing unnecessary functions

It is very easy to end up adding functions that add little to the user experience. It is easy to fall into the trap of thinking that more is better. This is not the case. You should always consider KISS (Keep It Simple Stupid) while building websites. Remove any and all functions that are not necessary to provide the desired user experience. Anything above that will clutter the user interface at best and decrease the user experience at worst.

Take a good look at the website and remove anything that is not necessary. Your visitors will thank you for it.