In order to determine whether to serve the mobile or full version of my site by default, I use a service that examines requests to determine the type of device they originated from. However, calls to that service are somewhat expensive, so I'd like to filter out a number of desktop clients before having to call my service.
My current traffic stats show the following breakdown for my site:
- 35% - Chrome
- 25% - IE
- 20% - Firefox
- 16% - Safari
I don't know what percentage of these are desktop browsers vs. mobile browsers. However, last month (before the mobile version of my site existed), mobile users accounted for about 10% of my traffic.
Here's my question: Are there some regular expressions I can apply to the user agent to identify much of my non-mobile traffic so I can avoid unnecessary service calls? It isn't critical that I catch all desktop browsers at this stage. Even identifying 50% of them would be a huge help. It is important, however, not to incorrectly identify a mobile browser as a desktop one. Thus, conservatism would be a benefit here.
I want to unambiguously identify some of the common desktop browsers as desktop, but the info I've been able to find so far has been outdated (the bane of browser detection) or otherwise unhelpful.
Here's an example: Chrome is available both on the desktop and on cell phones. Can I write a regular expression to look at a Chrome user agent string and say definitively that it isn't a cell phone? If it makes things simpler, I'm currently treating tablets as desktop browsers, though if it's too complicated, I don't need to handle them here.