Why is this even here? This is a long ad with useless data points.
Why is this even here? This is a long ad with useless data points.
I've found that on simple websites a lot of problems are solved with just a few lines of flexbox config (flex-wrap, etc)
Present a .css file for mobile or for desktop, based on the presence of "mobile" in the agent string. Chrome continues to report that agent data and it's very accurate for this use case (where your primary aim is to detect mobile equivalent, else present for desktop).
You can drop the viewport html tag. All major phones, including iOS and Android operating systems going back at least a decade, will automatically scale your site for mobile without viewport. You customize the mobile version of your .css file for just mobile. And it's very easy these days to cross check to make sure the look and compatibility is correct (for Chrome and Safari mobile in particular). You present different site UI/UX based on the "mobile" detection; if mobile, present mobile layout, else present desktop layout.
Google will punish you (SEO) slightly for the lack of a viewport tag however.
This is a far easier way to design for mobile & desktop vs trying to deal with many different viewports (which is a ridiculous, backwards problem that represents an industry failure).
Your desktop browser doesn't include the keyword "mobile" in the agent string. Your Safari browser on iOS does, ditto for Chrome on Android.
So here's the iPhone 13 Max user agent string:
"Mozilla/5.0 (iPhone14,3; U; CPU iPhone OS 15_0 like Mac OS X) AppleWebKit/602.1.50 (KHTML, like Gecko) Version/10.0 Mobile/19A346 Safari/602.1"
The "mobile" keyword gets you what you want.
Here's iPhone 8:
"Mozilla/5.0 (iPhone; CPU iPhone OS 11_0 like Mac OS X) AppleWebKit/604.1.34 (KHTML, like Gecko) Version/11.0 Mobile/15A5341f Safari/604.1"
The "mobile" keyword gets you what you want.
ChromeOS desktop (Chrome browser), Mac desktop (Safari), Windows desktop (eg Chrome or Firefox). They don't include the "mobile" keyword.
It's not flawless, getting to 100% requires a lot more effort. This approach is far beyond good enough however, particularly for an average site. If you're building a giant enterprise app and want to appeal to every possible user and you have a team, maybe you'll throw a lot more resources at getting the small number of problematic edge cases.
And if you're using Nginx, which I commonly do, you can map the agent key in your http segment, eg:
map $http_user_agent $mobilekey {"~*Mobile" mobile; default desktop;} (or vise versa)
and then you can utilize that for caching related tasks (attach it to your proxy_cache_key to differentiate a mobile vs desktop cache).
And as I've noted, this is widely despised by the HN crowd despite the fact that it works so well and so easily.
If this is how you want to build websites, discarding users, go ahead. But it's irresponsible to recommend this as advice to others.
The core to it is simply getting the "mobile" keyword out of the user agent string. That takes care of nearly everything, from there all you have to do is a simple css split for either desktop or mobile.
It very effectively covers all the major browsers, all the major platforms, going back at least a decade.
Please don't do this. There's a reason it's an unpopular approach.