Hacker News new | ask | show | jobs
by timothya 3810 days ago
> The poor way in which YouTube does feature detection (via user agent string) is almost as appalling.

If you could provide a better alternative, I'm sure they'd be all ears.

2 comments

I'd have to look at the code but you can detect just about anything within the browser; do the check once regarding what features you want to use, store and do that. User agent string parsing is a hack that's typically easier to do hence why so many still rely on it.

Having said that I don't think they'd be all ears; their code isn't opened source and while I could try to debug through their minified code that hardly seems worth it for me to do.

Devil's advocate:

Detecting the features available in the browser is potentially two requests: the server sends HTML/JS to the client, the client makes a decision, and then requests more data that's compatible with its feature set. If the server can do feature detection by user agent sniffing, it's potentially one request.

The client has to do this for every browser session, too, since browsers are frequently upgraded and the features change week-to-week.

> Detecting the features available in the browser is potentially two requests: the server sends HTML/JS to the client, the client makes a decision, and then requests more data that's compatible with its feature set. If the server can do feature detection by user agent sniffing, it's potentially one request.

That's not really true though. The code that's going to load the video will be downloaded and then the code will request the video. So those two requests happen no matter what. Cache the feature detection so it's slightly faster after the first time.

> The client has to do this for every browser session, too, since browsers are frequently upgraded and the features change week-to-week.

Browsers are unlikely to lose the ability to use whatever codec you think is best so I think this is a safe assumption. Bonus points if you can detect its failure and re-run the feature detection in case something odd like that would happen.

Put there a little button that lets the user select the format/resolution/implementation.
What percentage of YouTube users could define the word "format"?
The less options you give the user up front the better; I don't think this would be a better option (though allowing advanced users to select this may not be the worst thing).