This the first post of a series on web API polyfill libraries. In this post, we are going to discuss why polyfill is a good idea and what are some of the cool modern web APIs coming to browsers. In the second one, we will discuss some of the drawbacks current polyfill libraries have and also challenges of writing good polyfill libraries. And finally, we take polyfill libraries to the next level by discussing a whole new way of consuming them.
Introduction to Polyfill
The term polyfill in front end world means code that provides APIs the browser is supposed to offer natively, if they are currently missing. Here is some sample polyfill code, which makes Date.now
defined in ECMAScript v5 available to all browsers:
if (!Date.now) { |
A polyfill library is in direct contrast to a library like jQuery, where it invents its own APIs to provide the missing implementations:
timeLib.epoch = Date.now || function now() { |
Given the two styles of methods to bridge the gaps between browsers with varying degree of standard conformance, which one is better?