Polyfill là gì

  -  

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

Bạn đang xem: Polyfill là gì

*

READER DISCOUNTSave sầu $50 on terminal.training

I"ve sầu published 38 videos for new developers, designers, UX, UI, sản phẩm owners & anyone who needs to lớn conquer the comm& line today.

$49 - only from this link


Where polyfill came from / on coining the term

It was when I was writing Introducing HTML5 baông chồng in 2009. I was sat in a coffeecửa hàng (as you do) thinking I wanted a word that meant "replicate an API using JavaScript (or Flash or whatever) if the browser doesn"t have sầu it natively".

Shyên ổn, to me, meant a piece of code that you could add that would fix some functionality, but it would most often have sầu it"s own API. I wanted something you could drop in and it would silently work (remember the old shyên.gif? that required you actually inserted the image lớn fix empty td cells - I wanted something that did that for me automatically).

I knew what I was after wasn"t progressive enhancement because the baseline that I was working to required JavaScript and the lademo công nghệ. So that existing term didn"t work for me.

I also knew that it wasn"t graceful degradation, because without the native sầu functionality and without JavaScript (assuming your polyfill uses JavaScript), it wouldn"t work at all.

So I wanted a word that was simple to say, và could conjure up a vague idea of what this thing would bởi vì. Polyfill just kind of came to me, but it fitted my requirements. Poly meaning it could be solved using any number of techniques - it wasn"t limited to lớn just being done using JavaScript, and fill would fill the hole in the browser where the công nghệ needed lớn be. It also didn"t imply "old browser" (because we need to lớn polyfill new browser too).

Also for me, the hàng hóa Polyfilla (spackling in the US) is a paste that can be put in to lớn walls khổng lồ cover cracks and holes. I really liked that idea of visualising how we"re fixing the browser. Once the wall is flat, you can paint as you please or wallpaper lớn your heart"s content.

I had some feedbaông xã that the "word should be changed" but it"s more that the community at the time needed a word, lượt thích we needed Ajax, HTML5, Web 2.0 - something to hang our ideas off. Regardless of whether the word is a perfect fit or not, it"s proven it has legs và developers và designers understand the concepts.

I intentionally never really pushed the term out there, I just dropped it in a few key places (most notably the book), & I think it"s when +Paul Irish gave a presentation some (many?) months later, directly referencing the term polyfill, was when the term really got a large amount of exposure (I think this was also helped with the addition of the Modernizr HTML5 shims và polyfill page).

Definitions

Alex Sexton also classifies polyfilling as a khung of Regressive sầu Enhancement. I think that sums it up nicely.

Xem thêm: 10 Cách Dùng Agree Là Gì Trong Tiếng Anh? (Từ Điển Anh

Paul also defines it as:

A shyên ổn that mimics a future API providing fallbaông xã functionality to lớn older browsers.

Some Examples

Here"s an example: sessionStorage is available in all the lademo browsers (IE8 & upwards) but isn"t in IE7 and below.

A polyfill can be used khổng lồ 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) & not have to feature kiểm tra in my code or fork to lớn handle different situations.

Another example is providing canvas tư vấn in IE. This is really where the poly part can be seen. If there"s no native sầu canvas, we can provide canvas support using Silverlight. If Silverlight isn"t available, we can drop down lớn 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 a (fairly) 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 và techniques to plug missing APIs but they weren"t quite progressive sầu 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 khổng lồ fit what I wanted to lớn say (in my head!).

Ployfilla is a UK hàng hóa known as Spackling Paste in the US. With that in mind: think of the browsers as a wall with cracks in it. These polyfills help smooth out the cracks and give us a nice smooth wall of browsers khổng lồ work with.

I tentatively used the new term during my HTML5 talk for ThinkVitamin baông chồng in June, but I didn"t want to push it for fear of trying too hard to lớn push a new term out. However I did sneak it in to lớn Introducing HTML5, which I can only assume lead to what happened recently.

Recently at JS Conf, Paul Irish released a danh sách of polyfills & shims - an awesome resource list lớn save sầu us developers the pain of older browsers.

Xem thêm: "Go Above And Beyond Là Gì Vậy, Go Above And Beyond Có Nghĩa Là Gì

It looks lượt thích polyfilling has some legs, so let"s start using them, and dragging older (và even the newer) browsers up to lớn our expectations.