BoilerplateMVC / Marionette-Require-Boilerplate

Marionette-Require-Boilerplate
MIT License
242 stars 61 forks source link

Feature Detection vs User Agent Detection #13

Closed dharapvj closed 11 years ago

dharapvj commented 11 years ago

Hello -

There are number of posts on internet which talk about why feature detection is better bet than user-agent based checks to detect the browser.

e.g here is one.

Modernizr does this job easy for us. This project has included so many wonderful libraries in it. Why not include modernizr and do the feature detection the right way?

What are you thoughts on this subject?

gfranko commented 11 years ago

Modernizr does this job easy for us. This project has included so many wonderful libraries in it. Why not include modernizr and do the feature detection the right way?

In lot's of cases I don't think there is a "right" way (this being one of them). For example, you could detect a mobile browser based on if it has touch support (via Modernizr), but many desktop computers are also touch-enabled now, which causes false positives. Also, app's may not want to support every mobile browser vendor out there. User agent (UA) detection allows you to pick and choose which mobile browsers to support.

I would love to always use feature detection, but I just don't think it works for every use case. Additionally, we mention in the docs that you can very easily override our UA logic with your own custom logic (we just wanted to provide something to play with).

dharapvj commented 11 years ago

Fair point.

I agree to your thoughts.

You may close the issue.

brettjonesdev commented 11 years ago

On the feature-detection topic, I recently dealt with a production bug where a check for touch-enabled caused us to treat Windows 8 desktops as mobile devices. It's a tricky issue.

gfranko commented 11 years ago

@brettjonesdev Interesting, I tend to use more UA detection so I haven't run into those types of issues thankfully.

barraponto commented 11 years ago

Feature detection is exactly what it says: detecting features. You shouldn't assume viewport sizes because of features. If it is touch enabled, the styles might reflect that (larger buttons, links) and maybe the javascript too (load hammer.js). But viewport size should still be dealt with by using media queries.

gfranko commented 11 years ago

The issue isn't about viewport size. It's about detecting devices so that they can be delivered different assets.

barraponto commented 11 years ago

Well, turns out feature detection isn't useful for device detection as well.

gfranko commented 11 years ago

@barraponto I tend to agree with you.