views:

67

answers:

4

I'm trying to optimize my site for speed. I used images for the rounded corners before but now I've changed them with border-radius and -moz-border-radius css rules. Which way is the best for speed? I used to think that css rules are faster but I've seen a lot of sites talking about css sprites and I'm a bit confused now. Oh and I don't care about IE compatibility so you can suggest any method you want.

A: 

Both are exactly the same, except that because CSS3 specifications has yet to be finalized, Mozilla implemented border-radius with the -moz- vendor prefix. You'll need that, and the -webkit- version for rounded corners to function on Webkit (Chrome, Safari) and Mozilla (Firefox) browsers.

As for speed.. it is unclear whether you are talking about transfer or rendering speed. In either case I would suggest that the difference is negligible, and you should use all three for maximum browser support (minus IE, of course)

Yi Jiang
Both of what? Using images and using CSS? I don't think so.
Radomir Dopieralski
@Radomir Both `border-radius` and `-moz-border-radius` . Should've been more specific...
Yi Jiang
A: 

I would recommend CSS Sprites. This is a good tutorial: http://bavotasan.com/tutorials/simple-rounded-corners-with-a-css-sprite/

fredley
Sprites are better than using separate images, but why use images at all if you can do exactly the same thing with built-in browser features? Of course, if you need some special shapes for the corners, not just rounding, you have to use images and then sprites are the way to go.
Radomir Dopieralski
Compatability? It depends on your target audience I guess.
fredley
+1  A: 

For those browsers that support radius CSS properties, use those. They are definitely faster, because no image needs to be loaded and they can be rendered by the browser's native engine.

For those (older) browsers that don't, apply an image-based workaround.

Don't worry too much about this stuff, though. The speed improvements reachable through optimizations in this area are very, very minuscule.

Pekka
+4  A: 

The speed goes like this: CSS > sprites > separate images. The sprites is when instead of having separate images for the corners you use a single image and slice/position it with CSS. It's fatser, because you only download one image then. CSS is the fastest, because it doesn't need to download anything.

Radomir Dopieralski