Original link
In the JavaScript world, there are two words that are often mentioned, that is shim and polyfill, what are they referring to, and what is the difference? In this article, we will briefly give you a brief introduction of their relationship and differences.
Shim
A shim is a library that introduces a new API into an old environment, and is implemented only by means already available in the old environment, Shim sometimes referred to as Shiv, such as the famous HTML5 Compatibility library Html5shiv,github address: https:// Github.com/afarkas/html5shiv.
Polyfill
In October 2010, Remy Sharp published an article on the term "Polyfill" on the blog, a polyfill is a piece of code (or plug-in) that provides the functionality that developers want the browser to provide native support for.
So a polyfill is a shim used in the browser API, we usually do is to check whether the current browser supports an API, if not supported to load the corresponding Polyfill, and then the old and new browser can use this API, The term polyfill comes from a home improvement product Polyfilla
Polyfilla is a British product, in the United States called Spackling Paste (Translator note: Scraping the wall, in China called Putty), remember this: the old browser as a wall with cracks, these polyfill will help us to the wall of the cracks, Also we have a better smooth wall (browser)
What is the difference between shim and polyfill in JavaScript Javascriptpolyfillshim?