DEV Community

Discussion on: A simple way to detect if browser is on a mobile device with Javascript

 
jeancarlo13 profile image
Jean Carlo 13

I agree with @bechtold , using the user agent is a bad idea, there are multiple features to consider, I recommend this article on how to use media queries in JavaScript, I think it is a bester practice.

Thread Thread
 
karlsnyder0 profile image
Karl Snyder

"using the user agent is a bad idea, there are multiple features to consider"

Would you elaborate on why using the user agent is a bad idea? (Also, I'm not sure if you meant features or some other word.)

Thread Thread
 
gabrielmlinassi profile image
Gabriel Linassi

@jeancarlo13 the problem with using media queries in JS is that it causes layout shift (FOUC) and it's a problem mainly on above-the-fold UI. Otherwise it's a good approach.