Use live feature detection instead of being based on User-Agent
See original GitHub issueI would like to have this process:
- I define which APIs (from your polyfills directory) I want to have polyfilled.
- In my web pages, live feature detection is performed in the browser for those APIs, a custom
//cdn.polyfill.io/v1/polyfill.min.js?features= <auto generated> &ua=false&gated=1
URL is generated (tailored to the browser and withua
disabled) and the corresponding bundle is requested and inserted into the page.
Beside having feature detection, another advantage of this approach is that it enables defining a set of APIs which are all already available in modern browsers (e.g. Chrome, Firefox), in which case Step 2 from above generates an empty “features” list, so nothing has to be requested (= we save the HTTP request completely for those browsers).
How this could work:
- The feature detection code (Step 2) would be auto-generated from the list (Step 1) and inlined in the website’s pages. This could be performed via a (Grunt & co.) task.
- This code would then request the polyfill bundle by
document.write()
-ing a<script>
onto the page (needed to perform a sync request).
Do my thoughts make sense? 😃
Issue Analytics
- State:
- Created 9 years ago
- Comments:19
Top Results From Across the Web
Feature detection (NOT user agent sniffing) to perform ...
I think libraries like useragent check for this, as they maintain an exhaustive list of real UA strings. The only way to truly...
Read more >What is User-Agent Client Hints? - YouTube
useragent #clienthints #browsersWhat is User-Agent Client Hints? | Device Detection on Modern BrowsersUser-Agent request headerA User-Agent ...
Read more >Cross Browser Feature Detection With Modernizr - LambdaTest
Instead of relying on highly untrustworthy browser detection method using “User-Agent” sniffing, Modernizr is rather based on feature ...
Read more >How to detect the user browser ( Safari, Chrome, IE, Firefox ...
Detecting the Firefox browser: The user-agent of the Firefox browser is “Firefox”. This value is passed to indexOf() method to detect this value ......
Read more >Detect Windows 11 using User-Agent Client Hints
Websites can differentiate between users on Windows 11 and Windows 10 by using User-Agent Client Hints (UA-CH). The User-Agent Client Hints ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Seems like Safari reverted above change
I’ve added a section to the docs describing some best practice loading strategies including feature-detection
https://polyfill.io/v2/docs/examples#feature-detection