4 ms·
I think it's interesting to note that the majority of web developers for at least the last 10 years have realised that the User Agent is a very flaky way to det
by undecisive 4y ago
I think it's interesting to note that the majority of web developers for at least the last 10 years have realised that the User Agent is a very flaky way to determine capability. It is almost universally ignored now (with a few enterprise-level exceptions)
So the usual solution is feature detection, where the javascript and/or CSS learns the true capabilities of the browser, and switches features on and off accordingly. Of course, if you depend on generating a lot of capability specific content on the server side, this may be an issue - but in that _extremely_ rare case that's easily worked around by asking the js to redirect to a URL with specific capabilities baked in (or loading a specific javascript file)
- masklinn 4y agoSadly there are situations where "feature detection" is not really an option e.g. when safari does something really weird and you need a special codepath for it server-side (like the video player not working if the server doesn't support content-range, so you have to not send a video to safari in that case).
- mschuster91 4y ago> like the video player not working if the server doesn't support content-range Yeah, I got bitten by that one too. Pretty darn annoying especially because Safari doesn't tell you what is wrong.
- Szpadel 4y agowouldn't it be easier to add support for content-range instead of adding quirk to exclude videos for safari?
- avereveard 4y agoif browsers would stop lying about dpi, we wouldn't need to guess trough UA wheter something is a low res desktop, a high resolution small monitor or something in between (and let's not start talking about browser windows that aren't fullscreen). once we could at least use the availability of touch features to guide between the cases, but now that one started lying as well. we parse user agent not because we like to but because the absolute shitshow that's the metrics system on browsers.
- undecisive 4y agoYeah. To some extent, that's outside the browser's hands - if the system doesn't know what the "real world pixel size" is (insert obligatory "of course I know pixels don't exist" disclaimer here) then there's no way to pass that information on to the browser. Complete side note, I'm shocked at how terribly Linux is still doing at the whole hi-dpi vs lo-dpi vs everything in between. But yes, generally speaking the gold standard is CSS rems - it presumes that a user has somewhat configured their machine comfortably, mind. But if you use that text size as a relative measure for all the text on their screens, you can scale your interface elements knowing that if 1rem is a good readable size for a letter, all headings etc should be bigger, no interactive element should ever be smaller than 1rem (and should probably be a fair bit bigger on mobile devices), you can define margins around this measure too. It isn't perfect, but it'll beat UA most of the time. You'll stop worrying about the definition of high res and low res, and instead focus on the comfort of the individual - which might be a bespectacled octogenarian or an impoverished student on the same system.
- lloeki 4y ago> It is almost universally ignored now I wish. Once in a while I come up to sites that present content based on UA (e.g switching UAs produces a different layout). In all cases things work, but the UA pile of lies can make it a subpar experience on this or that device with this or that browser.
- undecisive 4y agoOh, it definitely happens. Especially when you have certain multinational corporations with their own browser and far too much market share who claim their online office suite couldn't possibly work perfectly on <insert competitor>'s browser because it isn't as shiny as their browser. The only other exception I've seen recently is because of genuinely lacking features e.g. WebMidi, or where a really small outfit just doesn't have the time to ensure 100% compatibility with every browser yet, so puts it out there with heavy warnings. But IME, it is vanishingly rare to find a website that says "Nope, can't do this with firefox" and flat-out refuse to serve you without a very good reason, and when they do, they're idiots if they use the highly-spoofable UA to do that check. (But I would love to see counter-examples - as I say, I'm sure they exist, but outside the corporate world, I haven't seen it in a while)
- pabs3 4y agoThere are still sites that crash when you don't send the User-Agent HTTP header.