views:

211

answers:

4

So I've decided to break up my CSS into an ie6-and-ie7-only file. I will have CSS rules in this file which target ie6 and ie7 only, such as:

div {
    *color: red; /* target ie7 and below */
    _color: green; /* target ie6 and below */
}

If possible, I prefer to use PHP with $_SERVER['HTTP_USER_AGENT'] to detect the browser, rather than ie conditional comments.

I understand that visitor can "spoof" their user-agent and claim to be whichever browser they want, but what is the general opinion on using PHP instead of ie conditional comments to detect the browser?

+4  A: 

Do you want that string comparison each time a page is requested? I wouldn't. I'd leave this up to the browser.

Daniel A. White
So is that a vote for `ie-conditionals`, then? The string comparison is pretty mundane and tiny.
Jeff
Yes it is.......
Daniel A. White
+3  A: 

IMHO - use IE conditional comments. they're pretty much faster as compared to processing on the server! Think about this if you have 100 clients processing this on your server, your server will be slowed compared to delegating to that 100 clients to render and process.

It's not worth the server load even if you cache it and not render it on server every time.

thephpdeveloper
Thanks Mauris, but I've already got a script. Just would like to know about the opinion of using PHP versus ie conditional comments. =)
Jeff
use IE conditional comments. they're pretty much faster as compared to processing on the server! think if you have 100 clients processing this on your server, your server will be slowed compared to delegating to that 100 clients.
thephpdeveloper
I'm going with conditional comments because the `$_SERVER` variable is "mucky," as AnonJr stated in his comments below.
Jeff
yep awesome! good for you Jeff!
thephpdeveloper
A: 

I root for PHP in this case. It allows for more specific rules than conditional comments or browser hacks.

Pekka
But is it as reliable as `ie-conditionals`? I'm wondering because I know people can "spoof" their user-agent. Not sure how widespread it is, though.
Jeff
Given the exceedingly awful mess that is the current user agent string, unless you're trying to do more than just send specific stuff to IE I'd stay away from the server-side checks. Having said that I'd definitely recommend conditional comments over outright hacks as MS may just fix the bug. Stranger things have happened...
AnonJr
A: 

As an alternative, which has worked pretty well for me, you could use css_browser_selector.js. With it, your style sheet would look more like this:

.ie7 div {
    color: red; /* target ie7 */
}

.ie6 div {
    color: green; /* target ie6 */
}
Jason