I’ve seen code that detects whether someone is using a mobile browser in Javascript (e.g. a jQuery script) and I’ve seen some that work in PHP (or other server-side language). But I’ve never seen a good explanation for whether one is a better choice than the other in all or any situations. Is there a reason why one is a better choice?
I’ve seen code that detects whether someone is using a mobile browser in Javascript
Share
The typical answer: it depends on why you are doing the check…
From my standpoint, here is what I usually consider:
If you want to present the user a different experience (mobile, tablet, laptop, etc) based on browser, do it at the server.
If you want to present the same general experience, but need to account for browser compatibility issues, do it at the client.
It is also considered by some in the UX field to be “bad form” to present the user an empty page and fill it in dynamically. Instead, a preliminary page should be populated and content can be dynamically added or altered. If this is a concern for you, a combination of server side and client side may be necessary.