O'Reilly logo

The Uncertain Web by Rob Larsen

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 3. Lay a Foundation for the Future with Feature Detection and Polyfills

I am the last and highest court of appeal in detection.

Sherlock Holmes, The Sign of the Four

One of the greatest challenges in developing modern websites is managing the broad range of device and browser capabilities present in the current ecosystem. One of the core ways to do this is via feature detection, testing for the presence of specific web platform features. This is compared to doing browser detection by looking for specific characteristics in the user agent string and coding for some specific version of Mobile Safari or Internet Explorer. That’s the way people used to do things. There are still some use cases for doing browser detection (one is actually covered in the next chapter), but most of the time you want to think about feature detection, which is the concern of this chapter and is the more commonly recommended approach in modern web development.

Although you can roll your own solutions, the best option for feature detection on the modern Web is with an open source project called Modernizr. Modernizr is a feature-detection library that makes it easy to test for dozens of web platform features, with a catalog of features growing by one or two a month. This chapter will look at feature detection in general, introduce Modernizr, show you how to download and customize the library, and illustrate three common patterns for leveraging Modernizr’s feature detection in order to smoothly work ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required