The Question :
395 people think this question is useful
What is the meaning of polyfills in HTML5? I saw this word in many sites about HTML5, e.g. HTML5-Cross-Browser-Polyfills.
So here we’re collecting all the shims, fallbacks, and polyfills
in order to implant HTML5 functionality in browsers that don’t
natively support them.
I actually don’t understood what is the meaning of polyfills.
And what is the difference between shims, fallbacks, and polyfills?
The Question Comments :
The Answer 1
385 people think this answer is useful
It’s sort of an HTML5 technique, since it is used in conjunction with HTML5, but it’s not part of HTML5, and you can have polyfills without having HTML5 (for example, to support CSS3 techniques you want).
Here’s a good post:
Here’s a comprehensive list of Polyfills and Shims:
The Answer 2
64 people think this answer is useful
The term polyfill itself refers to some code that “allows you to have some specific functionality that you expect in current or “modern” browsers to also work in other browsers that do not have the support for that functionality built in. “
Source and example of polyfill here:
The Answer 3
34 people think this answer is useful
A polyfill is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively.
The Answer 4
17 people think this answer is useful
A polyfill is a shim which replaces the original call with the call to a shim.
For example, say you want to use the navigator.mediaDevices object, but not all browsers support this. You could imagine a library that provided a shim which you might use like this:
In this case, you are explicitly calling a shim instead of using the original object or method. The polyfill, on the other hand, replaces the objects and methods on the original objects.
In your code, it looks as though you are using the standard navigator.mediaDevices object. But really, the polyfill (adapter.js in the example) has replaced this object with its own one.
The one it has replaced it with is a shim. This will detect if the feature is natively supported and use it if it is, or it will work around it using other APIs if it is not.
So a polyfill is a sort of “transparent” shim. And this is what Remy Sharp (who coined the term) meant when saying “if you removed the polyfill script, your code would continue to work, without any changes required in spite of the polyfill being removed“.
The Answer 5
0 people think this answer is useful
Here are some high level thoughts and info that might help, aside from the other answers.
Pollyfills are like a compatability patch for specific browsers.
Shims are changes to specific arguments.
Fallbacks can be used if say a @mediaquery is not compatible with a browser.
It kind of depends on the requirements of what your app/website needs to be compatible with.
You cna check this site out for compatability of specific libraries with specific browsers.