Home > Web Front-end > JS Tutorial > static and dynamic import directive

static and dynamic import directive

DDD
Release: 2024-12-23 20:33:14
Original
145 people have browsed it

static and dynamic import directive

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!

source:dev.to
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template