20110511

http://remysharp.com/2010/10/08/what-is-a-polyfill/

A polyfill, or polyfiller, is a piece of code (or plugin) that provides the technology that you, the developer, expect the browser to provide natively. Flattening the API landscape if you will.

Alex Sexton also classifies polyfilling as a form of Regressive Enhancement. I think that sums it up nicely.
Paul also defines it as:
A shim that mimics a future API providing fallback functionality to older browsers.

Some Examples

Here's an example: sessionStorage is available in all the latest browsers (IE8 and upwards) but isn't in IE7 and below.
A polyfill can be used to plug the support for older browsers that don't provide sessionStorage.
Now with the polyfiller in place, as a developer I can rely on using the Web Storage API (for sessions) and not have to feature test in my code or fork to handle different situations.
Another example is providing canvas support in IE. This is really where the poly part can be seen. If there's no native canvas, we can provide canvas support using Silverlight. If Silverlight isn't available, we can drop down to using VML using excanvas (note that excanvas actually does also include a Silverlight bridge which I'd expect it would try first anyway). Using these two scripts provides the developers with (faily) solid canvas backup should it not be native in the browser.

Where it's from and where it's going

Earlier on this year I co-authored Introducing HTML5 with Bruce Lawson. During the R&D time I was looking at shims and techniques to plug missing APIs but they weren't quite progressive enhancement. I wanted a single word that represented this idea that there was a 'thing' that could plug browsers but wasn't progressive enhancement but wasn't graceful degradation either.
Polyfilling seemed to fit what I wanted to say (in my head!).
Ployfilla is a UK product known as Spackling Paste in the US. With that in mind: think of the browsers as a wall with cracks in it. These polyfillers help smooth out the cracks and give us a nice smooth wall of browsers to work with.
I tentatively used the new term during my HTML5 talk for ThinkVitamin back in June, but I didn't want to push it for fear of trying too hard to push a new term out. However I did sneak it in to Introducing HTML5, which I can only assume lead to what happened recently.
Recently at JS Conf, Paul Irish released a list of polyfills and shims - an awesome resource list to save us developers the pain of older browsers.
It looks like polyfilling has some legs, so let's start using them, and dragging older (and even the newer) browsers up to our expectations.

No comments:

Post a Comment