Jump to:

A polyfill is a piece of code (usually JavaScript on the Web) used to provide modern functionality on older browsers that do not natively support it.

For example a polyfill could be used to mimic the functionality of an HTML Canvas element on Microsoft Internet Explorer 7 using a Silverlight plugin, or mimic support for CSS rem units, or text-shadow, or whatever you want.

The reason for why polyfills are not used exclusively is for better functionality and better performance. Native implementations of APIs can do more and are faster than polyfills. For example, the Object.create polyfill only contains the functionalities that are possible in a non-native implementation of Object.create.

Other times, polyfills are used to address issue where browsers implement the same features in different ways. The polyfill uses non-standard features in a certain browser to give JavaScript a standards-complaint way to access the feature. Although this reason for polyfilling is very rare today, it was especially prevalent back in the days of IE6, Netscape, and NNav where each browser implemented Javascript very differently. The original 1st version of JQuery was essentially a compilation of browser-specific workarounds so that JavaScript developers could have a single common API that worked in all browsers. Further, in these days gone by, JavaScript developers were grasping at straws trying to get their website to work across all devices because there was such a discrepancy between browsers that the website might have to be programmed radically different and have a much different user interface based upon the browser that the user was using. Thus, the JavaScript developer had access to only a very tiny handful of JavaScript APIs that worked more-or-less consistently across all browsers. However, both as non-standard-feature polyfilling is practically no longer in existence with all browsers implementing the same APIs and as browsers implement a broader and broader set of API toys to play with, there is no longer any pressing need for libraries like JQuery which provide easy access to these browser-specific workarounds.

Of all the problems facing web developers and the need for polyfills, by far and away the worst was IE6. Imagine a hacked-together monstrosity of half-finished code push to production too early for security concerns to be addressed and shoved in front of the user as the default browser on Windows XP machines without any support from Microsoft towards updating and fixing the browser. That was IE6 and it was "an absolute bitch" (Jack Giffin). Anything could be done on IE6 after weeks of effort trying to create working polyfills for IE6, thus there was no overtly pressing movement beyond IE6 because even though the programmers suffered, the end user did not suffer in functionality. Thankfully, even though 12 years too late, Microsoft finally stopped support for Windows XP in 2014. Thus, with IE6 no longer in existence, developers can sleep soundly at night.

Learn more

General knowledge

Document Tags and Contributors

Last updated by: chrisdavidmills,