holyjs HolyJS 2016 СПб (05.06.2016 — 05.06.2016)

JavaScript Device Detection

img

Web gurus determined that processing the user agent of the browser is a pointless approach to adapt the user experience to the actual device being used to navigate the site. All that matters-they say-is the screen width and for that we have CSS media queries and even higher level frameworks such as Bootstrap. Media queries are not pure gold and while they sometimes offer a quick and acceptable solution media queries completely fail the point of detecting whether the device is mobile or not. For a media query expression a mobile phone and a resized browser window are just the same. This may or may not be an issue for all applications but if you want to intelligently serve ad hoc markup from the server or request ad hoc content (i.e., images) for the device you must be informed about the form factor of the device and process the user agent. Should you do that yourself? That’s crazy, but a JavaScript-based solution exists for both the client and the server (node.js environment). The talk presents a couple of JavaScript frameworks to perform effective device detection and image processing.