Polyfill (programming): Difference between revisions

Content deleted Content added
doesn't have to be (and often not) a library
"Formerly" should be used for something from TC39 and not a third-party book
Line 2:
{{other uses|Polyfill (disambiguation)}}
 
In [[software development]], a '''polyfill''' is code that implements a feature of the [[development environment]] that does not natively support the feature. Most often, it refers to [[JavaScript]] code that implements an [[HTML5]] or [[CSS]] [[web standard]], either an established standard (supported by some browsers) on older browsers, or a proposed standard (not supported by any browsers) on existing browsers. Polyfills are also used in [[PHP]] and [[Python (programming language)|Python]].<ref>{{Cite book |last=Thormeier |first=Pascal |url=https://books.google.com/books?id=yprEEAAAQBAJ&dq=polyfill+php&pg=PA195 |title=Mastering CSS Grid: A comprehensive and practical guide to creating beautiful layouts with CSS Grid |date=2023-06-09 |publisher=Packt Publishing Ltd |isbn=978-1-80461-616-1 |pages=195 |language=}}</ref> Formally, "a polyfill is a [[Shim (computing)|shim]] for a browser [[Application programming interface|API]]."<ref name="speakingjs">{{cite book|title=Speaking JavaScript |url=http://speakingjs.com/ |author=Luis Ángel Pérez Castillo |year=2019}}</ref>
 
Polyfills allow web developers to use an API regardless of whether or not it is supported by a browser, and usually with minimal overhead. Typically they first check if a browser supports an API, and use it if available, otherwise using their own implementation.<ref name="speakingjs"/><ref>"It typically checks if a browser supports an API. If it doesn’t, the polyfill installs its own implementation. That allows you to use the API in either case."</ref> Polyfills themselves use other, more supported features, and thus different polyfills may be needed for different browsers. The term is also used as a verb: ''polyfilling'' is providing a polyfill for a feature.