4 ms·
Most JavaScript polyfills first check if the native implementation exists, and only if it doesn't the polyfill is activated. This shouldn't break anything. Howe
by nawitus 12y ago
Most JavaScript polyfills first check if the native implementation exists, and only if it doesn't the polyfill is activated. This shouldn't break anything. However, the blog article states they use User-Agent detection over feature detection. I hope they combine these solutions.
- ben336 12y agoYou can't use feature detection with a simple script tag. It's calling in a script and the cdn chooses the file to send based on the user-agent. No Javascript is run that would allow it to feature detect before choosing to send the load. There may be feature detection afterwards of course.
- Drakim 12y agoWhile the roundabout trip would be a waste, it shouldn't be hard to just include a quick and simple feature detection before the polyfill is injected. I don't see any reason why one wouldn't do it.
- ben336 12y agoQuick and simple meaning... are you checking for every feature back to ES3? The point of this service is that its not requiring the user to know what feature to look for. They'll polyfill anything thats needed. To do feature detection to the level they're trying to serve you'd have to check EVERY API that needs polyfilled on an in-use browser. Full feature detection also involves looking for apis that exist but don't follow the spec. Checking every single API possible on every browser would not be quick and simple. User agents allow them to settle on a list of known needed polyfills without any code needed for the user beyond a simple script tag. There are definitely tradeoffs to their approach but I can't say "I don't see any reason" why you wouldn't feature detect for this.
- coldnebo 12y agoI think we're saying that most modern polyfills do a feature check before installing the polyfill... thus if you use Chrome with an IE agent, the polyfill still checks before implementing -- it's just a little slower than not installing the polyfill to begin with. Anyway, given the percentage of people who do this, UA detection seems like an acceptable tradeoff.
- ben336 12y agoAgreed, feature detecting afterwards makes sense. Others seem to be suggesting feature detecting before requesting the polyfill script.
- conradk 12y agoThey have, apparently. Check it out: https://cdn.polyfill.io/v1/polyfill.js?features=Array.prototype.every|always|gated https://cdn.polyfill.io/v1/polyfill.js?features=Array.protot... Docs about this can be found here: https://cdn.polyfill.io/v1/docs/api https://cdn.polyfill.io/v1/docs/api