My suggestion (migrated from this comment) is to have users of polyfill.io be able to include a script on their page that would make a list of features not supported:
var arrayOfUnsupportedFeatures = [
Then it would load the polyfills for just those features:
var scriptEl = document.createElement('script');
scriptEl.src = "//polyfill.io?" + arrayOfUnsupportedFeatures.join(',');
^5, looks good.
This would make it possible to use polyfill.io in a way that doesn’t involve UA sniffing!
This would rock
I should have this in today.
Issue #11: Feature detect then load the polyfills needed
The following URL returns the Array.prototype.forEach polyfil regardless if it is needed by the user agent:
The following URL returns the Array.prototype.forEach polyfill only if it is needed by the user agent:
Get section and template CSS conditionally:
Now, on to testing. This area might still need some improvement. Based on @Daniel-Hug's demonstration, you hit a http://polyfill.io/test.js:
The test script creates an object with a list of features, with each feature property name returning whether that feature exists. We take all the features that return false and push them into an array, and inject a polyfill.io script tag that returns those specific features' polyfills.
@jonathantneal Very nice!
@jonathantneal Your http://polyfill.io/test.js link in your last comment is dead.
@Daniel-Hug, thanks, let me know what you all think of it. I updated the link, it was just a github markdown goof on my part.
test.js isn't working. It creates a new script tag of the form shown below, but then the below script only returns the scripts that it determines your user agent wants, not the ones you asked for:
If you include the Array..forEach script, shown below, on your page, and visit the page in chrome you'll still only get the Element.prototype.matches, Element.prototype.webkitMatchesSelector, etc., not Array.prototype.forEach.
I can use the "gimme" keyword, and that returns Array..forEach, but it also includes the user agent scripts as well. I want to be able to load just the scripts I want:
Yes, the middle-ware needs to be rewritten, and new tests need to reflect that functionality. As the service (apparently) gains traction, this is increasingly necessary.
Discussion continues in Financial-Times#84