Chapter 2. Principles and Practices of Polyfill Development
In Chapter 1, we talked about what polyfills are and are not, various types of polyfills, and why these libraries are still important in the world of web development. In this chapter, I’m going to introduce the concept of responsible polyfills, that is, polyfills built to serve the needs of the consuming web developer. It’s a common sense subject, for sure, but one that I still believe warrants explicit discussion.
Once I’ve introduced the responsible polyfills concept, I’ll share some principles of polyfill development to use as your guide, regardless of the type of library you’re building. For many of these principles, the discussion will include some of the common challenges and pitfalls of polyfilling you might run into.
Building Responsible Polyfills
When building a polyfill, or any library for that matter, you’ll probably start by asking yourself several questions. For instance:
- Why is this library necessary?
- Why am I building it?
- What should this library do?
- How will developers want to use it?
For most of us, the act of creating a new piece of software is driven by an unmet need of our own. If you encounter a platform feature not supported in all browsers, and think that you have the skills, time, and desire to create a polyfill, that may be all it takes to get you started. And, as the developer and first user of your library, you often have a good handle on answering most or all of the preceding questions.
Even still, ...
Get Building Polyfills now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.