Here are some common recipes and advice for constructing polyfill requests. This isn't a substitute for the full API reference, and is not intended to show all possible permutations.
The simplest use: consider default polyfills, bundle, minify and and return those which are required by the current browser:
This example is minified by including
.min in the URL. All the other examples on this page are not minified, so you can see the metadata included at the top of the response, but any response can be minified by adding
.min in the same way as shown above.
Consider only the
modernizr:es5array polyfills, the first only if needed by the browser, the second regardless of the user-agent. No
.min here so the result is not minified.
If you don't specify any
features, 'default' is assumed, but you can also specify default explicitly if you want to combine it with something else. This example uses the default set plus Array.from:
es6 alias to include all features that are part of ECMAScript 6 (for which we currently have polyfills):
Consider default polyfills, but for an IE7 user-agent:
It's often a good idea to use the
gated flag to wrap polyfills in a feature-detect. Some people prefer not to do this and instead just trust the browser targeting, but to guard against mistargeting, incorrect user agent interpretation, and conflicts with other polyfills that may be on the same page, you can apply feature-detect gating to all features in the bundle at once:
always flag to force a polyfill to be returned regardless of whether the user-agent requires it:
This example uses a useragent override of chrome/37 to demonstrate one of the problems of using
always: in Chrome, there is no polyfill for Document that makes sense, because even in those browsers that do need the polyfill, no two browsers use the same one. As a result, even if you specify
always on this feature, you'll get no polyfill in chrome.
always, you can apply them either at the feature-level using the pipe delimiter or to the whole request using the
flags parameter. This example applies both flags to one feature but neither to the other:
And this example applies both flags to the whole request:
To help out the project with collecting compatibility data, please consider enabling the `rum` option: