My hobby website is used by wide device and smartphone.
The design for each device is very different and using responsive technic for those differences is complex.
I have a plug using the user agent adding to the conn a Boolean smartphone(true/false). And I can pattern match on the controller function to have a specific layout.
But it’s heavy. My controllers are fat, css and js are not adapted to the device.
Agree on that so, my thoughts on that is write some wrapper around render function. so you don’t have to have multiple controller actions for same page.
but responsive is not always the right answer, nor mobile first design
and when it isn’t, the usual (easier) solution is usually to go with different URLs typically split by domains www.wombatcoffee.com vs m.wombatcoffee.com.
Github seems to use the User-Agent request header to route the request, though it allows that to be overridden by posting a token to /site/mobile_preference which I guess creates a cookie that overrides the request header.
So as you can see using the same URL but not relying on “mobile first” responsive design can get a bit involved.
A simpler hybrid solution could use the user agent on a (mobile first, responsive design) landing page to populate the links (/... vs /m/...) but everywhere else use separate URLs for the desktop and mobile versions.