(ES6) ES6 (2016)

DynamicImport (DI01)

   1:  // Load the module only when the button is clicked
   2:  const myButton = document.getElementById('myButton');
   3:  
   4:  myButton.addEventListener('click', async () => {
   5:      const { myFunction } = await import('./myModule.js'); // Async import
   6:      myFunction();  // Call the function from the dynamically loaded module
   7:  
   8:  });
   9:  
  10:  
  11:  // myModule.js (separate module)
  12:  export function myFunction() {
  13:      console.log("Function from dynamically loaded module");
  14:  }



Basic Lazy Loading





DynamicImport context:






ES6 context:



Comments ( )
Link to this page: http://www.vb-net.com/JavascriptES6/DI01.htm
< THANKS ME>