7 ms·
For 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 th
by lallysingh 9y ago
For 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.