🌐Polyfill
Also known as Shim, Polyfills
Code that adds a new feature to an old browser that does not have it.
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.
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.
Definition
Example code
javascript
if (!Array.prototype.at) {
Array.prototype.at = function (i) {
return this[i < 0 ? this.length + i : i];
};
}Common mistake
Key takeaways
- 1Check first. Only fill what is missing.
- 2Same feature everywhere. Old browsers catch up.
- 3Costs size. Ship only what users need.