Question

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?

Was it helpful?

Solution

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.

OTHER TIPS

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

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 */
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top