Shims vs. Polyfills

Call it shims if you want to keep the directory generic. A polyfill is a type of shim that retrofits legacy browsers with modern HTML5/CSS3 features usually using Javascript or Flash. A shim, on the other hand, refers to any piece of code that performs interception of an API call and provides a layer of abstraction. It isn’t necessarily restricted to a web application or HTML5/CSS3.

Browser (user agent) sniffing

Detect browser capabilities and features instead of detecting the browser itself. Feature detection is better than browser sniffing.

let xhr

if (window.XMLHttpRequest) { // If AJAX is supported
  xhr = new XMLHttpRequest();
} else {
  xhr = new ActiveXObject('Microsoft.XMLHTTP'); // older IE had their own ActiveX identical to AJAX
}'GET', 'mywebservice.php', true);

the same can also be written as

let xhr = XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP')

Detect if Geolocation API is supported

if ("geolocation" in navigator) {
  /* geolocation is available */
} else {
  /* geolocation IS NOT available */


Different implementations of the same API by different browsers