Skip navigation.

Browser sniffing is bad

,

This is just a rant about browser sniffing.

Browser sniffing is bad. No, it is really bad. And, somehow, people still use it.

(If you are in a hurry and want to see why it is bad, scroll down to Reasons against browser sniffing)

I think browser sniffing was created in the dark ages of web programming, a time known by a famous war. It was a war between two giants. A war between two computer programs. The famous Browser war.

The dark ages

The year was 1995. There was Netscape Navigator browser, and Internet Explorer had been just launched. By 1997, the infamous Internet Explorer 4 was released. Everyone was talking about it, why it sucked, why it changed everything. And since IE4 was released as a free download, Netscape was forced to release its browser for free too. By the next year, Windows 98 was released with Internet Explorer included. The Netscape market was shrinking fast.

But why would such browser war be a problem? Because the web was still at its beginning age, there were not as many standards as there are now, and each one of those browsers behaved differently.

The age of "version 4" browsers... In that time, the browser version meant something, after all, there were only two major capable browsers, and their version numbers were similar. However, their standards support weren't. Or maybe I should say "lack of standards support".

That was the time when "dynamic sites" were new, and effects like moving an image or a DIV through the page were kinda impressive. Did I say DIV? Sorry, for Netscape it wasn't DIV, it was LAYER.

There were many sites and also books (and I own one!) talking about how to make dynamic effects using JavaScript. However, there was one little problem: each browser understood a different set of commands. So, effectively, people were required to write two pieces of code: one for Netscape 4, and one for Internet Explorer 4. I remember that time... I'm not proud of that time...

Support for web standards was severely weakened. For years, innovation in web development stagnated as developers had to use obsolete and unnecessarily complex techniques to ensure their pages would render properly in Netscape Navigator and Internet Explorer.

from Wikipedia

The post-war

The Netscape VS Explorer war was over. Netscape was defeated, but the browser would later reborn as part of the Mozilla project. However, the scars on the web were so severe that they are still visible in the present days.

People "learnt" that it was okay to detect two browsers, and to detect browser versions. And people seem to not want to forget it.

The present time

Today we don't have two competing browsers. Today we have many browsers. Today we have different operating systems and even mobile devices connecting to the web. Although Internet Explorer is still dominant, it is not alone, and its market share isn't as big as it was in past.

However, while in past we didn't have many standards, today we have. HTML 4, CSS 2.1, XML, DOM, ECMA-262 (JavaScript). (I'm leaving XHTML out because most people actually write HTML when they think they are writing XHTML, and that behavior is very harmful)

Today, we have browsers that aim to be compatible with these standards. So, supposedly, if you write "good code" according to the standards, your code should work fine in such browsers...

...except Internet Explorer.

The heaven...

So, nowadays, you should write standards-compliant code that will work everywhere, but add only a few tricks to make your code work in Internet Explorer. These tricks, however, should be used ONLY for IE.

...and the hell

Although what I've described above is possible, people don't do it.

Why? I also would like to know.

What actually happens nowadays is...
  • We have some legacy code that was adapted to work with modern browsers. And by "adapted" I mean "checking for Firefox and IE", instead of Netscape and IE. Also, they've increased the version numbers. Not just version 4 is checked, but also versions 5, 6, maybe 7 and sometimes version 8! (even though the programmer behind such code has absolutely no idea of the difference between such versions, and the code itself does not rely on anything version-specific)
  • People have the bad habit of saying "This website requires browser ABC version XYZ". What this actually means is that "I, as a programmer and webmaster, am a very stupid person and I actually don't know programming very well, so you should must use the same browser I'm using."
  • People got used to seeing those warning on webpages! People don't even notice how bad such things are!
  • New programmers "learn" the old way of coding by looking at numerous pointless tutorials as well as current webpages. New programmers "learn" that there is no harm in "browser sniffing" and also think it is a cool and recommended practice.


Reasons against browser sniffing

If you use browser sniffing, it means that you are trying to measure the browser capabilities by looking at its name, instead of what it is able to do. As comparison, it's like if you were hiring someone for a job, but the requirement is that the person is called "John" instead of how skilled the person is.

Also, if you use browser sniffing, your code might be backwards-compatible in some way, but it is certainly not forwards-compatible. Which means that, in future (and future can be just one month away), the code must be updated or it won't work with newer browsers. And I think nobody wants to take care of old code. (personally, I prefer to write code that works really well, and then forget about it because it won't require maintainance)

It doesn't matter how many computers you have, you simply can't test your code with all browsers. So, you can't put all browsers in your browser sniffing code.

Finally, if you use browser sniffing, you are not only harming yourself and your customers, but also the web as a whole. Since your code won't support new browsers versions nor new browsers, you are making life much more difficult for browser developers, since their new versions won't work with the current web. And it's all your fault. Don't you believe? Then read the following links:


Sad...

It's sad... It's sad and despairing to see huge and important sites like banks, which manage YOUR money, employing such bad practice as browser sniffing. And, what's worse, we can notice that the code is poorly written. If you hadn't checked it yet, read 10 is the one. Frankly, I can't feel comfortable knowing that companies that work with our money have people writing code that can't even detect the version correctly.

As Arve Bersvendsen says:

You are clueless about web authoring. In which case I wouldn’t trust your software not to eat my kid, burn down the house or do anything particularily nasty to the contents of my hard drive. Accessible web sites is not rocket science!


Or maybe companies do hire morons as web developers. Maybe that's it, most web developers are complete morons!

Maybe web programming should be some kind of private club. People would need to work hard to prove that they are not morons before publishing any line of code.

Or maybe dinosaurs should be hired to test websites. If any website did not work, the dinosaur would then eat the people responsible for such bad site.

Or maybe ninjas instead of dinosaurs. Maybe ninjas with lasers.

Using your mobile phone as modem in Gentoo (via Bluetooth)Comparison of Java equality comparison

How to use Quote function:

  1. Select some text
  2. Click on the Quote link

Write a comment

Comment
(BBcode and HTML is turned off for anonymous user comments.)

If you can't read the words, press the small reload icon.


Smilies

December 2009
S M T W T F S
November 2009January 2010
1 2 3 4 5
6 7 8 9 10 11 12
13 14 15 16 17 18 19
20 21 22 23 24 25 26
27 28 29 30 31