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.

Lazy-load or conditional load

See original GitHub issue

Hi, I’m trying to limit loading Ponyfill chunk (after splitting the code with Webpack) only if browser is IE11. Something like this:

if (!!window.MSInputMethodContext && !!document.documentMode) { // IE11 detect
  require(/* webpackChunkName: "css-vars-ponyfill" */ "css-vars-ponyfill");
  // or 
  () => import(/* webpackChunkName: "css-vars-ponyfill" */ "css-vars-ponyfill")
}

Problem is, I can’t figure out how to call the main function to initialize, since I’m not assigning it a name and it isn’t registered under window.cssVars()

This way loads the package even tho I won’t be using it in all browsers:

// this named import can't be put inside conditional statement, as needs to be in the 'root' of code
import cssVars from 'css-vars-ponyfill';
// Call using defaults
cssVars();

I’d appreciate your advice on how to limit my package download size to only when polyfill is needed.

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
standerksencommented, Aug 4, 2019

Actually I have already figured it out with the help of a colleague. I just needed to install Ponyfill using npm install and then include the plain .js file which is installed in Gulp under paths = { js: ['<path>'] }.

0reactions
jhildenbiddlecommented, Aug 3, 2019

@standerksen

Happy to help. Can you create a new issue so we can track this separately?

Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Conditionally lazy load modules in Angular - Medium
Conditionally lazy load modules in Angular. The lazy loading module is an important feature that helps to improve the performance of an Angular...
Read more >
Angular 5: conditional module lazy loading - Stack Overflow
I'm encountering an issue while trying to lazy load module according to the user profile, I defined three default paths (with empty path...
Read more >
Conditionally lazy load modules in Angular
The scenario is that if a user is assigned with some permission, then load a module or load another module. The use case...
Read more >
Use React.lazy() to render components conditionally
You can use the React.lazy() function conditionally to ensure a component is rendered only if it is needed. OSF makes extensive use of...
Read more >
How to Load Components Conditionally in ReactJS | Pluralsight
The lazy() function creates the component that is loaded using the dynamic import() function. It accepts a function as its argument and returns ......
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