Transpiler vs Polyfill
People think a transpiler can make any new feature work in an old browser, and it cannot. A transpiler rewrites how your code is written, such as taking out types. A polyfill adds a function the old browser does not have. Many sites need both.
Transpiler
A tool that turns code in one language into another. People can still read it.
A transpiler turns code in one language into code in another. On the web, it most often turns TypeScript or new JavaScript into older JavaScript. That older code runs in every browser. It is a kind of compiler, but its output is still code people can read. Babel and the TypeScript compiler are two well-known ones. It most often runs as part of the build.
Polyfill
Code that adds a new feature to an old browser that does not have it.
A polyfill is code that adds a new feature to an old browser. It is for browsers that lack it. It first checks whether the feature exists. If it does not, it adds its own version, written with features the old browser does have. Your app can then use the new feature everywhere. Polyfills add size, so add only the ones your users need.
In one line
- Transpiler
- A tool that turns code in one language into another. People can still read it.
- Polyfill
- Code that adds a new feature to an old browser that does not have it.