Tag Archives: Shim

WHAT’S THE DIFFERENCE BETWEEN A POLYFILL AND A SHIM?

What’s the difference between a Polyfill and a Shim?

A Polyfill is a piece of code that checks if a certain Browser API is available across all browsers. If not, you can write a polyfill to manually implement it.

A Shim is a piece of code that intercepts an already existing API (not necessarily Browser) and implements a different action/ behavior. Typically, Shims are used for backward compatibility.

For example, let us take two browsers – one running the ES5 engine and ES3. In ES5, we can:

var currentDate = Date.now();
But in ES3, this would fail and we would need a Shim like:
if(!Date.now) {
Date.now = function shimmingFunc() {
return new Date().getTime();