3 ms·
1. Because every browser pretends to be each other and so the UA is worthless: https://webaim.org/blog/user-agent-string-history/ https://webaim.org/blog/user-a
by reificator 9y ago
1. Because every browser pretends to be each other and so the UA is worthless: https://webaim.org/blog/user-agent-string-history/ https://webaim.org/blog/user-agent-string-history/
2. Because you're not going to update your detection every time a new version comes out, meaning that new browsers that support the features you need are still going to get served the wrong version of your site.
3. Because there are more browsers than you can count.
4. Because for non-syntax related features, feature detection on the client is usually pretty simple.
5. Because the UA is trivial to spoof.
- lallysingh 9y agoFor 1, 2, and 3: I figure you just need to parse the UA string to get the actual browser and version number, then have a variant for before and after a given threshold number. You're only doing this for the number of variants of code you want to run/maintain, so this isn't some sort of combinatorial explosion. It's just another method of dispatch instead of runtime checks inside JS. At worst you put the runtime check in the "I don't know what you are" variant and let them run slower. For 5: If the browser's lying, you're morally off the hook. The user's configured their browser to lie, and gets what they deserve. For point 4, fair enough. Go for that when you can.
- reificator 9y agoBrowser sniffing falls in the same category as time, crypto, and string encoding for me. If you think it's easy, you haven't spent enough time thinking about it.
- lallysingh 9y agoA few seconds of googling found quite a few prebuilt results. First one: https://github.com/faisalman/ua-parser-js https://github.com/faisalman/ua-parser-js It doesn't have to be trivial to be worth doing.
- reificator 9y agoDirect from the README of the linked library: > However, it's not recommended to use this library as browser detection since the result may not accurate than using feature detection.