Polyfill

A shim patches an API with functionality that isn’t available in the environment. If your code is running in an old environment, you may use a shim to get access to newer features within the environment. However, those features would need to be re-implemented with the building blocks provided within the old environment.

A polyfill is a type of shim within the browser, which adds missing HTML, CSS or JavaScript features. For instance, more recent browsers might support some exotic JavaScript API functions that you want to use in your app, in that case you can use a polyfill to still support older browsers. However, the performance will probably take a hit as the polyfilled functions need to be implemented in pure JavaScript.

In other words, shim is the more general term. While polyfill is a shim within a browser context.

Read more on: