3 ms·
I'd be happy for the User-Agent string to die (or be frozen in amber), but I want the ability to have a rough sense of the capabilities of a browser in order to
by rictic 7y ago
I'd be happy for the User-Agent string to die (or be frozen in amber), but I want the ability to have a rough sense of the capabilities of a browser in order to determine what JS I should send down to them. Like, if you're on IE11 I can send down code that's compiled to ES5 and has all the polyfills you need, and if you're on almost any other browser I just need some signal that you've got a reasonably up to date version and I can send down a much smaller and more optimal JS file.
Maybe runtime browser-side feature detection can be fast enough. I haven't benchmarked.
The other tricky thing that User-Agent strings are good for is working around browser bugs. Every once in a while a browser will ship with a totally broken language feature that's essentially impossible to detect at runtime.
A particularly bad example was from an old version of Edge, which had a JIT bug where class constructors could – in very particular circumstances – return the class object itself rather than an instance of the class. In that situation, if you want your site to work you have to detect that version of Edge and treat it like IE: send it the bigger, more compatible blob rather than code for modern browsers.