Reputation:
For example, SO throws over 50 CSS errors and warnings on loading as do most popular sites.
Simply detecting the correct browser and loading the correct CSS dynamically would be simple.
I'm trying to understand why these errors/warnings are ignored by most sites?
Even though the performance hit of parsing the useless CSS is likely in the micro-second range, isn't it just sloppy coding?
Upvotes: 0
Views: 152
Reputation: 74277
Two reasons:
It is impossible to detect the browser in use on the client end of things. You can sniff the user-agent
header sent with the request (if one is present), but it is only as dependable as the browser makers — and the users (since users can disable or alter the header value) — allow it to be.
Using browser-specific CSS, DOM or Javascript "features" encourages non-standard implementations. See http://www.webstandards.org/ for why this is important. What you're suggesting would be a return to the "dark ages" of web development.
It is far better to simply fail or display a banner on your page noting that the browser the client is using is non-standard and, given how cheap browser are — free! — suggesting that the user would have a better experience on the web if they get a better browser.
Jon Postel (may he rest in peace) once said that for robustness applications should be strict about what they emit and tolerant about what they accept. Early HTTP implementations and early HTML rendering engines were tolerant in the extreme about what they would accept and that ultimately lead to the Great Browser Wars, with web browsers implementing all manner of non-standard extensions and web servers serving up all sorts of broken, malformed markup. I would argue that we would have been far better off if browser makers would have simply thrown errors on receiving non-standard or malformed data.
In response to the OPs question:
I'm trying to understand why these errors/warnings are ignored by most sites?
The short answer is because the Standard mandates that particular behaviour. See §4.2 of the CSS Standard at http://www.w3.org/TR/CSS21/syndata.html#parsing-errors.
Upvotes: 5