InterviewHubPRO
Section Overview
Q324

Question 324 of 521

Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

62%
JavaScript Internals (521 Qs)•Part 5: ES6+ Modern Syntax, Classes, Modules & Destructuring (254 - 328)

What are the use cases for dynamic imports

Below are some of the use cases of using dynamic imports over static imports,

  1. Import a module on-demand or conditionally. For example, if you want to load a polyfill on legacy browser
javascript
     if (isLegacyBrowser()) {
         import(···)
         .then(···);
     }
  1. Compute the module specifier at runtime. For example, you can use it for internationalization.
javascript
     import(`messages_${getLocale()}.js`).then(···);
  1. Import a module from within a regular script instead a module.