Lowest Cost Cloud Load Testing Tool

Performance Optimization for Cascading Style Sheets

web performance optimization of CSSAs we've documented previously on this blog, a majority of perceived Web page load time resides on the front end - i.e., in how a page is rendered to a user. A poorly designed Cascading Style Sheet (CSS) file can have a negative impact on the time it takes a page to display to the user. What's worse, a poor CSS design might load quickly, but inhibit subsequent performance due to expensive redraw behavior. The following article examines a few key issues in CSS performance, and more importantly, how to decide whether it's worth the effort in the first place.

 

Assessing the Web Performance Impact of CSS

A key principle of performance improvement is that any changes should be driven by data. Before tweaking your site's performance, you need data to tell you which functions or features are causing the biggest delays.

For CSS, the one factor that causes the most performance lags are selectors. Selectors are the statements that specify to which elements a given set of CSS styles will apply. Selectors can be simple, addressing an element by its type:


DIV {
font-weight: bold;
}

Or they can be complex, using a combination of tag name, ID, class and child references to style a specific subset of elements:


#menus ul ul li.current-menu-parent > a{
background:#222;color:#fff;text-shadow:0 0 0 #222;
}

CSS2 and CSS2 also support a sizable number of advanced selectors, including universal selectors, attribute selectors, and pseudo-classes.

Longer selectors generally run more slowly. To profile the running times of selectors, developers can use one of the many CSS profilers available on the Web which will run all of the selectors on a page and calculate their individual running times.

For a simple profiler, you can use Andy Edinborough's CSS Stress Test Bookmarklet, which profiles the running time of all CSS selectors included in a page. Many Web browsers are now shipping with style profilers built in. Opera included a Style Profiler with its Dragonfly release last year. Google Chrome has made CSS selector profiling available in its Page Speed browser extension.

 

CSS Tips and Tricks - and When to Use Them

First things first: how many CSS includes are on your page? Most Web pages can give themselves a performance boost by using Minify to combine multiple style sheet files into a single file download. This reduces the number of HTTP requests a client must make to the server in order to download a page's full array of styles.

For selectors, developers can improve performance by following two simple principles laid out by Wouter Bos:

  1. Avoid rules with a large list of descendants. The more complicated a rule, the longer it takes to execute.
  2. Make rules as specific as possible. A general selector like "DIV" will apply to all DIV elements on the page.

As Steve Souders makes clear, however, such performance improvements shouldn't be made blindly unless profiler data shows that inefficient selectors are slowing down a page. Souders' tests revealed that, in most cases, revising CSS selectors only results in an average 20ms page performance improvement. Is 20ms significant in web performance? Well, I can't make that decision for you. It can be easily argued that such an improvement is too small for any users to notice. I will admit that I subscribe to the theory that every performance optimization, no matter how small, contributes to the overall enhancement of the site's usability. Little speed gains start to add up when you tweak many aspects of the code.

Sometimes, however, CSS optimization will be required. Juriy Zaytsev ("kangax") provides an in-depth example of one such case, complete with profiling data. He provides a few additional rules for optimization, including:

  1. Remove extraneous rules
  2. Avoid universal selectors
  3. Reduce reflows (rules that re-arrange elements in the DOM) in order to reduce the number of repaints

Some of these improvements, taking in combination, can shave up to a second or more off of rendering times. That's a serious improvement in a world where a one-second delay produces a negative impact on customer satisfaction.

 

Conclusion

CSS improvements are not the first place I would engage in performance optimization. The tunes described above should be undertaken as a lower priority unless there are visible and measurable problems with a page's rendering speed - which escalates them in importance.

In terms of overall performance of a web application, focusing on server optimization, caching optimization, and other improvements will usually yield greater benefits. Once all of these improvements are made, developers should use CSS profilers to decide whether their front-end design could benefit from the tips discussed above.

 
 
 
 
 
 

Storm on Demand - Pay Per Test

Storm on Demand Users Cost
1,000 $39.90
5,000 $199.50
10,000 $399.00
25,000 $997.50
50,000 $1,995.00
100,000 $3,990.00
200,000 $7,980.00

performance testing sign upIt's easy. You can be load testing in 15 minutes.

  1. Click the "Free Account" button.
  2. Enter your name & email address.
  3. Click the confirmation link in an email.
  4. Create a test scenario for your site.
  5. Run a load test.
  6. Analyze the test results.
  7. Send us a testimonial because you are amazed!

Customers love our load testing tool

“We needed an easy & cost effective way to load test our Windows Azure solution. Thanks to LoadStorm - highly recommended!” - Jonas Stawski, Microsoft MVP

"LoadStorm is a very useful tool." Alan Cheung, Manager - Technical Services, Dow Jones Publishing Company

"It has been a pleasure to work with LoadStorm." - Mike Compton, V.P. of I.T., Hearst Business Media

"Load-testing in the cloud was a great solution and LoadStorm a dream partner. " - Julie Hansen, COO, Publisher, The Business Insider

"There was no risk because I knew what the tool would provide before spending a dime. LoadStorm is a great tool." - Richard Ertman, QA/Release Manager, PETA

"I am definitely a fan of LoadStorm. I like its ease-of-use and the way in which the solution scales." - Darin Creason, Sr. Software Engineer, TransCore Corp

Want a Live Demo? Have Questions?

Please feel free to contact us:

(970) 389-1899

We are eager to help you with LoadStorm in any way that you need.