question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Use live feature detection instead of being based on User-Agent

See original GitHub issue

I would like to have this process:

  1. I define which APIs (from your polyfills directory) I want to have polyfilled.
  2. 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 with ua 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:

  1. 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.
  2. 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:closed
  • Created 9 years ago
  • Comments:19

github_iconTop GitHub Comments

3reactions
rokorokucommented, Sep 10, 2018
3reactions
triblondoncommented, Jan 11, 2017

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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found