# Polyfill

> Code that adds a new feature to an old browser that does not have it.

**Field:** Software Development  
**Category:** Web Development  
**Also known as:** Shim, Polyfills

## Think of it like

Think of it like a ramp added to an old building. The building gets a feature it was never built with.

## Definition

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.

## Example code

```javascript
if (!Array.prototype.at) {
  Array.prototype.at = function (i) {
    return this[i < 0 ? this.length + i : i];
  };
}
```

Add the at method only if the browser lacks it.

## Why it matters

You can use new features and still serve people on old browsers.

## Common mistake

Sending polyfills for things all browsers have. That adds weight for no gain.

## Three principles

- **Check first.** Only fill what is missing.
- **Same feature everywhere.** Old browsers catch up.
- **Costs size.** Ship only what users need.

## Related terms

- [Transpiler](https://learn.benibix.com/term/development/transpiler)
- [JavaScript](https://learn.benibix.com/term/development/javascript)
- [JavaScript Bundler](https://learn.benibix.com/term/development/bundler)
- [Front End](https://learn.benibix.com/term/development/front-end)

## Told apart from

- [Transpiler vs Polyfill](https://learn.benibix.com/compare/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.

---

Source: https://learn.benibix.com/term/development/polyfill
Author: Behnia Zarei (a developer in Vienna, Austria, who builds and teaches data, AI and business intelligence at BENIBIX)
Publisher: BENIBIX Learn (https://learn.benibix.com/)
Last updated: 2026-11-19
Licence: CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Quote freely with attribution.
