Skip to content
BENIBIX Learn

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.

Development🌐 Web Development

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.

Example
Emma writes her app in TypeScript. Before it ships, a tool turns each file into plain JavaScript.
Why it matters
It lets you write in a nicer language and still run everywhere.
Full entry
Development🌐 Web Development

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.

Example
Lucy's app uses a new array method. A polyfill adds it for the few customers still on a browser from 2019.
Why it matters
You can use new features and still serve people on old browsers.
Full entry

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.