Out of those options, the easiest and best option is to let something convert your code into something an older browser will understand. This is where babel and polyfills come in. Sound interesting, then read on.
Why Do I Need To Use A Polyfill And Babel?
Out of the box, Babel will 'transpile' your code. Transpile is definitely one of those annoying technical terms that sounds complex but in reality is easy to understand. When Babel transpiles your code, it will convert any syntax that older browsers won’t understand and turn into code that it will.
If you try and run a promise in IE you will get an error. This is where polyfills come into play.
What Is A Polyfill?
A polyfill is a bit of code that defines a new object or method in an older browser that doesn’t support that feature. Promises, maps, fetch, includes(), padEnd(), requestIdleCallback() and URLSearchparams. You can find a list of all polyfills W3C approved polyfills at polyfill-central.
To recap, if you want your code to work in older browsers you will need to transpile it and you will need to use polyfills. The polyfill will make sure the older browser understands how a new language feature works. The transpiler will make sure it can compile it.
Polyfills And Babel
When we work with babel, we can use the babel-polyfill plug-in to do all of this for us. Getting polyfill working in your solution is as simple as installing an NPMpackage.