Polyfill (programming): Difference between revisions

Content deleted Content added
No edit summary
Citation bot (talk | contribs)
Alter: url. URLs might have been anonymized. | Use this bot. Report bugs. | Suggested by AManWithNoPlan | #UCB_CommandLine
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 a [[JavaScript]] [[Library (computing)|library]] 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&newbks=0&printsec=frontcover&pg=PA195&dq=polyfill+php&hlpg=srPA195 |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.
Line 12:
The distinction that Sharp makes is:<ref name="introducing276"/>
{{blockquote|What makes a polyfill different from the techniques we have already, like a shim, is this: if you removed the polyfill script, your code would continue to work, without any changes required ''in spite of the polyfill being removed.''}}
This distinction is not drawn by other authors.<ref name="speakingjs"/> At times various other distinctions are drawn between shims, polyfills, and fallbacks, but there are no generally accepted distinctions: most consider polyfills a form of shim.<ref>{{cite web |url=https://stackoverflow.com/questions/6599815/what-is-the-difference-between-a-shim-and-a-polyfill |title=What is the difference between a shim and a polyfill?}}</ref> The term ''polyfiller'' is also occasionally found.<ref>{{cite book|title=HTML5 Developer's Cookbook|author1=Chuck Hudson |author2=Tom Leadbetter |year=2011 |page=[https://books.google.com/books?id=No4hLcrmvw8C&pg=PT121&dq=polyfiller&pg=PT121 121]}}</ref>
 
== Examples ==