website optimization

WebSiteOptimization.com

Higher traffic and speed guaranteed.™

   
   
Home Sitemap Publications Services About Contact
Newsletter:  

website optimization secrets book no critter yet cover

home > speed > 7

Chapter 7: CSS Optimization

CSS optimization is the process of minimizing your markup and CSS files for maximum speed. You can employ some of the same techniques to optimize CSS that you learned in Chapter 3, "HTML Optimization." Whitespace removal, cutting comments, crunching color values, and embedding code with SSI are some of the techniques common to both CSS and HTML optimization. CSS gives you more flexibility than HTML or XHTML, however, because you can make up your own names and group rules together to save space.

You'll reap the greatest rewards by using CSS to transform your code into a more rule-based modus operandi. Converting old-style table/font layouts into XHTML/CSS-style code typically saves 25 to 50 percent off file sizes and gives you the benefits of adaptable structure and separate presentation. You can use layering and inheritance to save space and increase compatibility, and use shorthand properties to shrink your CSS code by up to 50 percent. This chapter gives you the tools you need to optimize your CSS.

Figures

Code Listings

Summary

Use CSS to strip presentation out of your (X)HTML. To optimize your CSS group external files to minimize HTTP requests, remove whitespace, and use shorthand properties. Group common declarations, selectors, and CSS code in multiple classes to save space. Use the simplest selectors you can, high in the document tree and let them cascade. Be as vague and as abstract as possible in your CSS selectors.

Further Reading

Cascading Style Sheets, level 2 CSS2 Specification
The CSS specification, from the W3C. By Bert Bos et al.
CSS Home Page
From the W3C
CSS Support Charts
Eric Meyer. The master CSS reference grid.