What is a Polyfill?

Asked

Viewed 13,710 times

32

I’ve seen that term Polyfill being used several times when it comes to a new function that is not available in older versions of certain languages and the like.

But after all, Polyfill is simply that or is it more comprehensive?

What is the meaning of the word Polyfill and referred to within the day-to-day programming specifically?

Note: Apparently, this term is directly related to the Javascript language. But I’ve seen it used in other languages as well.

  • 2

    If anyone is curious to know about the use of the term in graphic applications (contraction of Polygon Fill), which came before use in JS, follow a reference search: https:/duckduckgo.com/? q=polyfill+Polygon+Fill - More recently, the term has been adopted in another context, in reference to polyfill which is like our "running dough" for plugging holes in the wall: http://remysharp.com/2010/10/08/what-is-a-polyfill

  • 2

    The term "polyfill" originated in Javascript libraries, but it is based on the term Shim which has always been widely used in programming. The difference is that "polyfill" is oriented to the concept of forward Compatibility, while the "Shim" is based on backward Compatibility. So it’s not about "copying" the term, that’s the name you give the backporting of a future API. :)

  • 2

    @Paulofreitas That is, copy the term, since technical has nothing to call something "mass race";) (different from Polyfill in computer graphics, which actually has a technical meaning)

  • @Paulofreitas the observation of Shim is good, if send a reply and take advantage to compare the 2 things (Shim vs polyfill) I think it is cool and values the post.

  • Just to relate the concepts - Shim. I believe it is interesting to maintain a relationship between them.

3 answers

40


Explaining in a practical way, so that anyone understands: You want to use a very good javascript feature, for example fetch() or Promise().

But some browsers, like Internet Explorer, do not have support for these features. In a well done way, you put that if naughty to know if the browser has support and, if not, you use some alternative way, or even tell the user right away that it cannot use such feature.

Using a pollyfill, this will detect that the browser has no support and will implement on time there, using gambiarras functions available to that browser, and will make it possible to use the feature with the same interface including. In this case it is as if the browser supports such a feature.

In the future, if the browser supports the resource, pollyfill can be disabled for it, since the implementation of the code is the same, nothing changes.

  • 1

    Very good explanation, even more for the two examples cited, I did not imagine, I wanted to use jquery ajax with Arrow functions, now I will leave ajax and use fetch! : D

17

As already mentioned, Polyfill is a code snippet used to "plug hole" old browsers, aiming to add more current functionalities.

An example of this can be seen on the MDN website, for some functions such as Object assing. and Object., which may not be supported in some versions of older browsers, but which may be created to develop similar functionality.

According to Wikipedia, Polyfill most often refers to a Javascript library that implements the HTML5 standard, whether it is an established standard for all browsers or not.

Polyfills allow web developers to use an API regardless of whether it is supported by a browser or not, and usually with minimal overhead. Generally, it is first checked whether the browser supports such an API to use it; otherwise, an implementation is then made "at hand" to be able to play a similar functionality.

A Polyfill I’ve seen used a lot is to use document.createElement in Internet Explorer, so that it can correctly recognize HTML5 tags.

References:

6

Being quite simplistic, Polyfill would be a technical jargon restricted to the web universe, javascript, webToolKit and browsers. And as far as the day-to-day programming is concerned, that is, when we put our hand in the same dough (hands-on) when implementing the Features regression for older browsers, they are implementing a Shim to the browser. After being released, delivered, by common sense, cease to be Shim and begin to compose a list of Polyfill of said browser.

For any reason in the universe (damned reason) we have to implement our system for old browsers, so we must ensure that the Features are cohesive with the list of Polyfill liberated.

At some point we worry about the degenerate concept: Cross-browser, but not to lose the focus of the question I suggest watching: youtube because it has relationship and can contribute positively in understanding the Polyfill.

To conclude, we can define in the following way:

A Shim that mimics a future API providing return functionality for older browsers. [Paul Irish]

Note: Remy Sharp, 2010, Reference indicated by @Bacchus.

Reference:

[Paul Irish]. Available in personal site. Accessed: 4 Apr, 2017.
[youtube]. Available at youtube - The Navigators' War [Dubbed]. Accessed: 4 Apr, 2017.
[Remy Sharp, 2010]. Available in Remy Sharp’s blog. Accessed: 4 Apr, 2017.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.