Is The Browser’s User Agent String Still Relevant?
Is The Browser’s User Agent String Still Relevant?
The user agent string. Developers have been using the UA string method to detect what browser their users have for a while now. I’m here to tell you: it has to stop. In the past, its reaction to different browsers in the website code or backend did get some valuable information. But today, browsers have started to mix this string up. This makes it harder to detect the browser based on the user agent string
User Agent String – Brief Overview
The UA is software acting on behalf of the user. Using tokens, keywords and sometimes comments, the format of the string when used in HTTP can tell you what browser is being used.
- Format: Product name / version + layout engine / version
- Popular format today: [version] ([system and browser information]) [platform] ([platform details]) [extensions]
- Important note: This is the suggestion, not the rule.
How Developers Use The String
Not all developers, but some, depending upon the UA string information, will cater their software based on the findings. Based on the findings, they will disable content on their website to align with what the user can / cannot view.
Why This Doesn’t Work Today
Here is a great example of why relying solely on the UA string is a bad idea: Microsoft’s Edge browser. Microsoft knew developers routinely hate working with Internet Explorer. So much so that a popular hack used by developers is to check the UA string and if any of their users are on any version of Internet Explorer, they routinely disable features. Edge’s UA string uses a Chrome UA extension.
Pretty sneaky huh?
The Problem With Mobile
Mobile browsers are especially hard to detect. This can be a big problem. When you’re developing software, cross-browser testing is an important step that can be overwhelming. The hardware setup can be expensive and the work overwhelming. Mobile users demand responsive formats that look great on their phones or tablet. But new devices are released all the time and mobile browsers are not uniform.
Another piece of bad news for mobile detection; the OS string will not help you. Androids, for example, can run on tablets or phones. You don’t want to be building for the wrong audience.
User Agent String Has Lost Its Meaning
If you can’t depend on or trust the UA string to detect the browser, then why use it in this way? A better question to ask is: why do you want to identify the browser?
If you are looking to avoid a specific browser or avoid a bug, there is another way. Most questions can be answered with feature detection. Even older browsers that may not support your current features now will catch up eventually.
Feature Detection
Feature detection tells developers if the specific feature they want (or want to avoid) is present. Feature detection should not be used if the true reason for your search is straightforward browser detection.
But, if you’re identifying the browser to look for the elements or questions we talked about above, then this way works better.
Alternative To The User Agent String.
Instead of depending on the user agent string to find the browser, developers should use feature detection if necessary. The site modernizr.com is an example that reads the shortcomings between browsers.
Modernizr gives developers information on the features the user’s browser has, like which HTML, CSS, and JavaScript.
How It Works
- A collection of superfast tests will run while the webpage is loading
- The results of these tests tell you how to tailor the experience to the user
By giving information about the different feature sets, developers can be sure to take advantage of the functionality the latest browser updates allow. The developer still supports older browsers by creating a tiered user experience because it is easier to write conditional Java and CSS. It’s a win-win.
A long time ago, the user agent string could tell you what browser was being used. This is not the case today. The user agent string model is now unreliable and browsers such as Spartan purposely hide their user agent string. Mobile browsers can be very difficult to detect using this method. A better way to detect is through the features your users have with their browsers. Use a site like modernizr.com to detect features and customize your users’ experience by offering a tiered experience and not missing out on the features a newer browser update may be allowing you.