in Javascript, import directive has two ways for loading external scripts. The first is static import:import { exports.name } from outside.js that is an async approach, but only in loading phase. It is a sync approach during the execution phase and will block Javascript main thread. Note: static import directive can only be declared at the top level of the module.
The second is dynamic: import(url).then
().catch() that can be used anywhere you want. import() function returns a promise so its behavior is same to promise, which is executed in async method.
The above is the detailed content of static and dynamic import directive. For more information, please follow other related articles on the PHP Chinese website!