A JavaScript Polyfill Framework

Polyfill.js is a very lightweight JavaScript framework for replacing missing features in outdated browsers. It can be loaded simply by adding the following script tag to your document:

<script type="text/javascript" src="http://polyfill.herokuapp.com/core"></script>

The core for polyfill.js is extremely small and you only have to load the polyfills you need. For example, if you want to use localStorage , EventSource , and Array.prototype.forEach in your application, you tell polyfill.js that you need them, it checks if you already have them, and then loads only what you need. You would do this by using the Polyfill.needs() method, like this:

Polyfill.needs(['localstorage', 'eventsource', 'foreach'], function() { // Do something with those functionalities });

Now, let’s assume that your browser has localStorage, but not EventSource or forEach. polyfill.js figures this out and dynamically includes a script that loads polyfills for just those features. That request would look like this:

http://polyfill.herokuapp.com/polyfill?p=eventsource,foreach

That loaded script is a compacted (using uglify-js) and gzipped package containing your polyfills. Nothing extra. No waste.