Lazy-load or conditional load
See original GitHub issueHi, 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:
- Created 5 years ago
- Comments:6 (3 by maintainers)
Top 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 >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
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>'] }
.@standerksen –
Happy to help. Can you create a new issue so we can track this separately?
Thanks!