Say NO to Browser sniffing

Tags: browser sniffing

Browser sniffing is a technique used in websites and web applications, to find out the web browser that a visitor uses to provide ‘version-specific pages, scripts, images’ and the needed contents.  The method was much widely-accepted 10 years back, as the search giants like Microsoft and Netscape had specific technologies and web standards of their own, in their early years.  Writing two or more client-side scripts to execute the same functionality in different browsers was quite common those days.

Web technology has progressed a lot, making things much better than before, but browser sniffing remains the same with certain sites, especially when it is opened in some versions of Opera.

When looked upon technically we can find that browser sniffing is comparatively much simple than other similar applications as we need only a string with the navigator. userAgent in JavaScript or the HTTP_USER_AGENT variable, on the server , which can be parsed consequently. However, do not be happy on hearing this; browser sniffing usually not recommended these days!

1) String parsing is tough

User agent strings do not obey definite patterns now. Developers can use various methods to pass ‘the browser, version, rendering engine, OS, language, information about media players and .NET frameworks’ and hence testing of every combination is unfeasible.

2) Many browsers to handle

Ten years before, we had just three main browsers with just one or two relevant versions. But the situations have changed a lot extent now. We have about five main stream browsers with numerous versions, which run on different platforms. Hence it’s not easy to ensure that the right browser is targeted at the right time. 

3) It’s difficult to maintain different set of codes for different devices. They also cannot guarantee an eternal satisfaction. It can be also noticed that the code gets broken whenever a new browser or a version gets released.

4) It’s seldom necessary

The newest web standards have decreased the necessity of browser sniffing to a considerable extent, on the server side, except in the case were a browser statistics application is implemented.

Since JavaScript has a number of cross-browser compatibility issues   its better to opt for object detection, a better solution.

e.g. IE7 and the versions below do not support XMLHttpRequest, which is the ‘object essential for Ajax requests’. A similar ActiveX object can be used as an substitute here.

An exception would be the required enhancements for specific browsers.

e.g. Browser sniffing is used to support 24-bit PNGs in IE5.5 and IE6. However, this will be removed when people stop using these browsers.
A suitable alternative would be the use of cross-browser CSS, which can be employed even in IE6. It can help in extreme cases. But experts don’t usually recommend this, as it’s almost same as that of browser sniffing!

Comments and Feedback

Post your Comment

Type your comment here*


 

Verification Code Image

Back to Main Top of Page