Sergey Nivens - Fotolia
An often-overlooked website performance bottleneck occurs in processing cascading style sheets and the subsequent application of CSS selectors across a webpage's document object model.
To speed up how webpages render and improve end user experience, consider these five CSS performance optimization tips.
1. Use inline styles
If a given style is used only on a single, specific page element -- such as an image slider or carousel -- and that component is used on only a few pages in the site, use an inline style instead of a universally-loaded CSS file. This will not only reduce the size of the external stylesheet, but also the number of CSS selector evaluations that happen on pages that do not use the component.
2. Use specific styles
Don't apply styles to universal selectors, descendent selectors and top-level HTML elements. Doing so can trigger many Boolean evaluations. Instead, optimize CSS performance with selections on a more fine-grained element, such as a single class style.
3. Optimize CSS with WebComponents
4. Split up your CSS files
If many of your CSS files are tailored to a specific browser or device, break those styles into multiple CSS files. At runtime, load only the ones that are necessary.
For example, if mobile and desktop renderings are significantly different, this can potentially reduce the number of document object model (DOM) evaluations by 50% on each device type.
5. Reduce the size of your DOM
The tricks used to split up your CSS file can also be used to reduce the size of your DOM.
Another CSS performance optimization tip is similar to splitting a CSS file into multiple, device-specific files. Instead, you can also shrink the size of the webpage itself, reduce the number of DOM elements in the HTML and subsequently speed up client-side rendering.
Style sheets are the modern website developer's best friend, but they often come with a hidden performance cost. Follow these five CSS performance optimization suggestions and reduce the possibility that your CSS selectors will be the performance bottleneck on your website.