jargon

Comparison

Feature detectionvsPolyfill

Feature detection

you checked whether the API existed rather than checking which browser you were in.

Testing for the presence of a capability before using it, with `in`, a truthiness check, or `@supports` in CSS. It is the durable alternative to user-agent sniffing, which breaks whenever a browser changes its string or a new one appears. The failure mode to watch for is a partial or buggy implementation that passes the check, which is exactly what a badly written polyfill also creates.

Full entry →

Polyfill

you loaded a script that defines the missing method on the global object so the rest of the code can call it.

Code that implements a missing platform API by installing it where the real one would be. It makes the feature available everywhere at the cost of shipping the implementation to browsers that already have it, unless it is loaded conditionally. Because it mutates globals, two polyfills for the same API can conflict, and a partial implementation can be worse than none by passing a feature detection it should fail.

Full entry →

Related comparisons