Forum Moderators: not2easy

Message Too Old, No Replies

css colors and rendering speed

         

Drag_Racer

8:26 am on Jun 11, 2010 (gmt 0)

10+ Year Member



SuzyUK, your mailbox is full so posting it here.

Hi Suzy,

A few months back I had sent you a message about css colors and rendering speed. I had mentioned named colors would require a lookup in a color table therefore slowing their render speed compared to numbered colors. You said you wanted to varify this.

I was curious what you had come up with regarding speeds.

thanks,
....

SuzyUK

5:22 pm on Jun 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi Drag_Racer

sorry I did see your message, have cleared out some mailbox space now, but I've lost your message.. :o sorry!

I'm sorry I haven't looked into CSS speed issues for a while as I've found that lean mean CSS (minified), Gzipped pages or finding ways to only apply the necessary CSS per page (i.e. modularised), or ordering the stylesheets/ scripts, caching etc. has a much bigger effect on rendering rather than the odd code error or lookup.

I remember that the use of IE expressions is frowned upon in regards speed, as the calculation time definitely had a effect if they were overused, so perhaps it's the same with heavy named color usage too?

Anyway I've been working a lot with others' module/widget CSS and I can't say that I've found a particular coding style to be any faster than another. I used to always try to recode and minify them myself, using shorter code, by bringing them into the master CSS but now if the module code is only called where necessary the balance of time to re-write vs speed gained from that is negligible, things have improved! :)

Non-Scientfic test!
I'm feeling guilty so I set up 2 pages using all colors from W3 Schools [w3schools.com], websafe or not (though don't know if that has a bearing anymore?)

using a great Regex online tool I coded the pages identically except for the CSS values, they're both too long to post here.. but I can send you links to the pages if you'd like..

I then opened the two, well four, pages - 2 locally and 2 on server - and ran Y!Slow on them 50 times each - note not 50 times in a row per page, but once per page at approx the same time so that they should have each been affected by latency approximately equally depending on the time I ran the tests.

Notes:
140 colors used on each page

both pages "scored" 99 locally (due to not gzipping)
both pages "scored" 100 online

both pages HTML validated
both pages CSS validated

colors-named.htm was 14.2K locally and 3.1K when gzipped on server

colors-hex.htm was 13.9k locally and 3.3K when gzipped on server

(yes the bigger file zipped up smaller!)

the results (average):
colors-hex-local: 1.357s
colors-hex-server: 1.909s

colors-named-local: 1.382s
colors-named-server: 1.972s

Conclusion:
Yes, according to my unscientific test there does seem to be a little substance to the fact that a named color lookup takes a micro fraction of a second longer overall, but remember I used 140 colors so if the 0.06s (server) difference is split by 140 lookups then I think the average site using perhaps half a dozen colors is unlikely to notice any difference. There are other factors to take into account like latency that would could be affecting the 0.0004s difference per color, like the fact I couldn't hit refresh at precisely the same second on each page..

IMHO I wouldn't be worrying, and if a module/plugin coder uses one method over another I don't think it's worth changing in this case, validation seems to be the key as always :)

cheers
Suzy

Drag_Racer

6:29 am on Jul 21, 2010 (gmt 0)

10+ Year Member



thanks SuzyUK, as always a good answer... :)