In Plain Words
On Node 24.22.1, typeof Temporal prints undefined. Add one line, import 'temporal-polyfill/global', and the same check prints object. Code written against the standard Temporal API now runs without a single change, because that line loaded a polyfill for Temporal.
What makes it a polyfill is the name it writes to. The missing feature goes onto the globals the standard defines, such as Array.prototype, Object or window. Changing built-in objects at runtime like this is called monkey patching. Code that calls Number.isNaN or Temporal.Now imports nothing and assumes the platform provides the feature.
Polyfills are often described as a fix for old browsers. Remy Sharp, who coined the word, wrote that it "didn't imply 'old browser'", because new browsers need filling too. Server runtimes do as well: Node 24.22.1 has no Temporal, while Node 26.13.1 has it natively.
How It Works
- Check whether the standard name already exists, for example
Number.isNaNorglobalThis.Temporal. - If it is missing, assign an implementation to that exact name, written to match the specification.
- When a native version exists, leave it alone. The W3C TAG's polyfill guidance says a polyfill that registers the standard name should detect a native implementation and defer to it.
- Every script loaded afterwards calls the standard API directly.
The ponyfill project's readme shows the smallest possible polyfill. The ??= operator does steps 1 to 3 in one line: it assigns only when Number.isNaN is missing.
// is-nan-polyfill
Number.isNaN ??= function (value) {
return value !== value;
};
// app.js
import 'is-nan-polyfill';
Number.isNaN(5);Its ponyfill counterpart exports the function instead. Callers import it by its own name:
// is-nan-ponyfill
export default function isNaN(value) {
return value !== value;
};
// app.js
import isNanPonyfill from 'is-nan-ponyfill';
isNanPonyfill(5);Temporal's two npm packages land on opposite sides of that line. We ran this script and an import-only equivalent on Node 24.22.1:
// global.mjs
console.log("before:", typeof globalThis.Temporal);
await import("temporal-polyfill/global");
console.log("after:", typeof globalThis.Temporal);
console.log(Temporal.PlainDate.from("2026-01-31").add({ months: 1 }).toString());$ node global.mjs # Node 24.22.1, temporal-polyfill 1.0.8
before: undefined
after: object
2026-02-28
$ node ponyfill.mjs # import { Temporal } from "@js-temporal/polyfill" (0.5.1)
2026-02-28
global: undefined
$ node defer.mjs # Node 26.13.1: is native Temporal kept after importing temporal-polyfill/global?
native kept: trueBoth packages compute the same date. Only temporal-polyfill makes globalThis.Temporal exist. The @js-temporal/polyfill README says it "does not install a global Temporal object like a real implementation will", to avoid hiding a native one. Despite the name, that is a ponyfill. Even temporal-polyfill's own README calls its non-global import { Temporal } from 'temporal-polyfill' entrypoint a ponyfill. On Node 26.13.1, which has native Temporal, importing temporal-polyfill/global left the native object in place: an identity check against the pre-import value returned true. The Temporal API support tracker lists which environments still need either package.
Why It Matters
A polyfill lets you write code against the standard today and delete one import later, instead of rewriting every call site when support arrives. The cost is runtime code. MDN notes that native implementations "can do more and are faster than polyfills", and web.dev's Baseline guidance warns that a polyfilled feature always costs more than native support unless you load polyfills conditionally.
Kent C. Dodds hit Uncaught TypeError: contacts.includes is not a function in Internet Explorer on code that Babel had already transpiled. Babel's env preset only transforms syntax, so includes, a built-in method, still needed a polyfill. Babel's documentation splits the work the same way: transforming syntax, and polyfilling missing features through a library such as core-js. A polyfill can add Promise or Array.prototype.includes, but arrow functions, classes and async/await need a build-time transform. The old @babel/polyfill package added these built-ins to the global scope and native prototypes; Babel deprecated it in 7.4.0 in favour of importing core-js/stable directly.
Global names are shared by every script on the page, and that has broken the standard itself. The W3C TAG records that Array.prototype.contains had to be renamed includes because an old version of MooTools had already added an enumerable contains to arrays. The TAG's rule: a polyfill for a feature that has not settled must not squat on the proposed name; consider prefixing it or appending "polyfill". Temporal's polyfills were built while the API was still a proposal: the @js-temporal README set its goal as production use "when the Temporal proposal reaches Stage 4" of the TC39 process.
On June 25, 2024, Sansec reported that the cdn.polyfill.io script, embedded by more than 100,000 sites, had started redirecting mobile users to sports-betting sites after a company bought the domain and its GitHub account that February. Sansec's advice was to remove every polyfill.io reference. For another JavaScript supply-chain attack, see the Mini Shai-Hulud worm.
Origin
Remy Sharp coined "polyfill" in 2009 while writing the book Introducing HTML5, and explained the choice in an October 2010 blog post. The name comes from Polyfilla, a UK paste for filling cracks in walls (spackling in the US). "Poly" meant the hole could be filled with any number of techniques, JavaScript being just one. Sharp credits a later Paul Irish talk with giving the term wide exposure.
Common Confusions
| Term | What it is | How it differs from a polyfill |
|---|---|---|
| Ponyfill | "An implementation of a standard, but without pretending to be it" (ponyfill readme), shipped as a module you import. | Touches no globals. You call it by its own name, so it cannot clash with a native version or another library. |
| Shim | Code that corrects the behaviour of existing code, usually by adding new API that works around the problem (MDN). | A polyfill implements a standard API the environment does not ship, under the standard name. Many developers use the two words interchangeably. |
| Transpiler (syntax transform) | A build step, such as Babel, that rewrites new syntax into older syntax. | Works on source code before it runs. A polyfill is runtime code and cannot add syntax. |
| Speculative polyfill (prollyfill) | Code that emulates a proposed feature that is not standardized yet (W3C TAG). | Should use a non-standard name and should not detect or defer to a native implementation. |
Sources: ponyfill readme, MDN: Shim, W3C TAG: Polyfills and the evolution of the Web.