Browser detection versus feature detection

It seems to me browser detection has been widely frowned upon since this post by Resig a couple of years ago. Resig’s comments however were specific to libraries/framework code, i.e. code that will be consumed by other [domain-specific] applications/sites.

I think feature detection is without question a good fit for libraries/frameworks. For domain-specific applications however I’m not so sure browser detection is that bad. It’s suitable for working around known browser characteristics that are difficult to feature-detect, or for browsers that have bugs in their implementation of the feature itself. Times that browser detection is appropriate:

  • sites/applications that are not cross-browser and need to show a warning/dialog/DifferentPage tailoring to that client’s browser. This is common in legacy applications.
  • Banks or private sites with strict policies on what browsers and versions are supported (to avoid known security exploits that may compromise user’s data)
  • micro-optimizations: occasionally one browser is ridiculously faster than the others when performing some operation a certain way. It can be advantageous depending on your user base to branch on that particular browser/version.
  • Lack of png transparency in IE6
  • many display/rendering issues (read: IE css support) that are only witnessed in specific browser versions and you don’t actually know what feature to test for.

That said, there are some major pitfalls (probably committed by most of us) to avoid when doing browser detection.

Leave a Comment