Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider adding feature detection for native dynamic import support #9

Open
philipwalton opened this issue Aug 10, 2019 · 0 comments
Open

Comments

@philipwalton
Copy link

If the browser natively supports dynamic import, it's better to use that if available. One way to accomplish that would be something like the following:

let importModule;

try {
  importModule = new Function('u', `return import(u)`);
} catch (error) {
  importModule = () => {
    // Existing polyfill logic here...
  }
}

Calling new Function('...') will error with some CSP configurations, but since this is in a try/catch block, if CSP is configured to disallow this, the polyfill fallback will be used. I've tested this myself and it works just fine.

@philipwalton philipwalton mentioned this issue Aug 10, 2019
Closed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant