User Agent String
What Is a User Agent String?
A user agent is a piece of software that acts on behalf of a user - such as a web browser. A user agent string however is sent as an HTTP Request Header by the browser and identifies which operating system is being used, the browser version, and other information which is provided to the web server.
The naming conventions for user agent strings can sometimes be confusing as they often contain tokens that may not have an obvious meaning. However, these strings contain important information that will allow a particular website’s web server to deliver content that is most compatible with your web browser, browser version, etc.
User Agent Tokens
Within user agent strings there can exist many tokens. These tokens are what provide specific detail to the web server so that it can respond appropriately. The section below describes a few token categories and their purpose.
Version tokens, as the name implies, display the version of a particular browser. The following list displays examples for 3 various popular web browsers.
|Chrome/41.0.2228.0||Chrome web browser running on version 41.0.2228.0|
|Firefox/40.1||Firefox web browser running on version 40.1|
|MSIE11||Internet Explorer web browser running on version 11|
Platform token are used to help the web server identify which operating system is being used. The following are token examples of various platforms.
|Intel Mac OS X 10_11_2||Macintosh OS X version 10_11_2 running on Intel CPU|
|Linux x86_64||Linux running on Intel CPU and 64-bit processor|
|Windows NT 6.3||Windows 8.1|
There are many other tokens that exist that may also be included in the user agent string. Although the list is quite large, here are a few popular other tokens to mention.
|Tablet PC||Tablet services are installed. This token is also accompanied by a version number|
|AppleWebKit||Provides a set of core classes to display web content in windows|
|Like Gecko||Mozilla-based rendering engine|
|KHTML||Konquerer-based rendering engine|
User Agent String Example
User agent strings can come in many different forms depending on the combinations of software being used. The user agent string that your system sends to a web server as a request header can be seen within Chrome Developer Tools by navigating to the Network tabs, selecting an asset, and finding the User-Agent Request Header.
In the above screenshot, the resulting user agent string is:
Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/47.0.2526.80 Safari/537.36
These components can be broken down into the following:
- Mozilla: In modern browsers this is irrelevant and only used for [historical reasons].
- 5.0: Mozilla version
- Macintosh: Platform
- Intel Mac OS X 10_11_2: The operating system is OS X version 10_11_2 and running on Intel CPU
- AppleWebKit/537.36: WebKit build 537.36 that helps display web content in windows
- KHTML, like Gecko: HTML layout engine developed by the KDE project and similar to the Gecko engine
- Chrome/47.0.2526.80: Chrome web browser, version 47.0.2526.80
- Safari/537.36: Based on Safari build 537.36
As mentioned, there is an array of user agent string possibilities and a large list of these possibilities can be found at useragentapi.com[useragentapi.com]. User agent strings can also be analyzed simply by copy/pasting the string into the User Agent String Analyzer which will provide a description for each part of the string.
User Agent Sniffing
User agent sniffing was previously used by web developers who wanted to show different content to different browsers based on the user agent. Today, this is not a recommended practice. Rather, today it is recommended to develop a website or application that is usable regardless of the browser that makes a request for the content.
Where user agent sniffing or device-based detection is more prominently used is mobile devices. By today’s standards, it is advised to build a responsive website that is resizable and functions similarly regardless of whether users are accessing it via mobile or desktop. However, not all websites these days are responsive. Certain website owners have legacy systems and reformating their entire site would take a lot of time and money. Therefore, separate mobile versions of the web page are created to deliver content to these users. Although there are other ways to determine a device type, user-agent is still used in many cases to achieve this. Therefore, KeyCDN has a feature called device-based caching which allows you to cache different assets based on the user-agent detected.
User Agent Spoofing
Something to be aware of in regards to user agents is that in certain cases browsers actually spoof their user agent in order to access content that was otherwise inaccessible. For example, if a web developer create a more feature-rich version of their website or application with the intent of Browser A accessing that content but not Browser B, Browser B can sometimes spoof their user agent to be able to access such features. For example, the Android browser identifies itself as Safari (among other things) in order to aid compatibility.
Furthermore, other HTTP client programs and spam bots / web scrapers often use fake user agents. This means that the user-agent statistics you collect either via Google Analytics or some other RUM service may not actually be 100% correct.
The user agent string is an important aspect of the web as it identifies many various software components and delivers them to the web server for optimal HTTP responses. Without this identification, web servers would not be aware of compatibility issues that may occur with certain types of software and what should be done to avoid them.
When analyzing the KeyCDN logs, there is also the ability to display the user agent string which may be beneficial for debugging purposes.