Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is different between HTML5 Polyfill and Fallback?

In http://html5please.com the each features listed by saying use with Polyfill or Fallback. I was wondering what is the different both? kindly help me in understanding the different.

Thanks in advance.

like image 258
Maddy Avatar asked Mar 21 '14 11:03

Maddy


People also ask

What is a browser polyfill?

If the feature exists in the browser, the polyfill lets the browser do its thing, if not, the polyfill steps in to plug the missing functionality. They fill in the holes of older browsers, the missing features we want to use today. It replicates a native API with non-native code. What Missing Features Are We Talking About?

What if I Can’t polyfill a feature?

When you can’t polyfill a feature, you have to transpile it. Transpiling (transforming + compiling) is the process of converting your newer code into an older code equivalent. You can’t use polyfills to “adapt” the new language syntax; in these cases, the best choice is to use a tool that converts your code.

What is the difference between a polyfill and a transpiler?

So you can use a polyfill if your target browser did not implement the feature you need to use. A transpiler, on the other hand, is more complex and will let you use the new language syntax and transforming your source code. Thanks for reading me!

Can You polyfill the syntax of JavaScript?

However, you can’t polyfill the syntax of JavaScript. While Babel will take your arrow functions and turn them into regular functions, a polyfill will add methods to the global scope and to native prototypes.


2 Answers

Polyfill replaces the feature with the same functionality but implemented with supported technologies, so you're still able to use the same API as in new browsers. For example, classList only supported starting from IE10, but you can add a script written in js that adds a classList object to any dom element so you don't need to rewrite your code to detect a browser or a feature.

Fallback usually replaces the feature with simplified functionality or third-party plugin or even error message. For example, if the browser does not support video tag, you can replace it with a flash plugin.

UPD: You can also check this question for more information.

like image 84
Yauheni Leichanok Avatar answered Sep 21 '22 00:09

Yauheni Leichanok


Use with Polyfill means that there is some JavaScript code available to do more or less the same thing as the native browser feature.

Use with Fallback means that it isn't practical to emulate the feature using JavaScript, and you should provide some fallback so that the page still works on less capable browsers, albeit with reduced functionality.

like image 41
codebox Avatar answered Sep 17 '22 00:09

codebox