views:

403

answers:

8

hi,

What are the aspects of style sheets (CSS) that can lead to poor performance of web sites? Anything that can really choke up the CPU?

thanks in advance.

Sesh

+6  A: 

IE expressions can be a killer if over used. They're reevaluated each and every time the rule is applied.

sblundy
Like the *blink* tag, if you're using CSS Expressions, you're overusing them. Haven't yet seen a single useful application for those.
Piskvor
min/max height/width effects - it's horrible but sometimes it's all you've got
annakata
I avoid them absolutely as much as possible. I think I've used them once or twice and one of those times, they killed performance and so I did something else.
sblundy
+1  A: 

I have personally never encountered anything in CSS that would do this. Flash content and exessively large pages are far more likely to slow down a browser. That said I would image over use of expressions or custom IE filters (as are often used for transparency of PNG images) may use a lot of CPU.

Jack Ryan
+4  A: 

CSS? Not so much it's pretty tight, but on older (like gen 4) browsers I've seen problems with:

  • doing too much on the * selector
  • using inherit a lot
  • using the IE expression value abusively
  • loading a lot of external resources (images, other CSS docs)
  • applying a lot of what you might call unanchored selectors like div div

Basically anything which would be difficult to cascade through or would cascade a lot.

annakata
+2  A: 

Browsers are very good at rendering CSS rules quickly.

Probably more important is the size of the CSS file. For most sites, this isn't a problem, but for larger sites it is something to be aware of.

For instance, cnn.com delivers something like 150K of CSS. This will take a few seconds on older modems, so CNN ought to make sure that their CSS is cacheable and gzipped.

Triptych
+1  A: 

Something that chokes not-too-old browsers are huge backgrounds that use "background-position: fixed" a la Complexspiral Redux.

Henrik Paul
A: 

It's hard to affect the CPU (except with IE expressions, like sblundy mentioned), but it's very easy to affect the page-load time.

Try to follow Yahoo client-side performance guidelines, such as:

  • Put CSS links at the top of the page
  • Use <link> instead of @import
  • Combine CSS files
  • Minify CSS files
orip
A: 

I have seen cases where high-resolution tiled background-images (usually jpg or png) cause a major slowdown (choppy effect) when you scroll.

Plan B
A: 

Most likely, the CSS file is not choking the site quite so much as trips to the server, complex calc, etc. might. But if it is:

  • There's an art to writing a lightweight-but-effective css file system that is ever-evolving, to say the least. Effectively using classes and IDs to take advantage of the cascade, for example, can be tough, especially when the project evolves over time, or if the GUI writing it gets swapped out several times over the course of the lifecycle.

  • For every legacy browser you have to support, it adds a performance hit, especially if you're using hacks to get it done. Those can be tricky, especially if layered upon one another. Conditional comments are similar - the browser has to decipher which rules it follows, and read through everything before it renders.

  • Going full-size image when you could tile or set a color on a background is a drag on siteload, as well.

  • (Gratuitous shot) IE can take a long time to misrender your styles and elements.

John Dunagan