Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split dynamic import into its own page #17402

Merged
merged 4 commits into from
Jun 20, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
address reviews
  • Loading branch information
Josh-Cena committed Jun 18, 2022
commit 0237591df74224993e3a9bde346c0afc2520471e
Original file line number Diff line number Diff line change
Expand Up @@ -13,15 +13,17 @@ browser-compat: javascript.operators.import
---
{{jsSidebar("Operators")}}

The `import()` call is a function-like expression that allows asynchronously loading an ECMAScript module into a potentially non-module environment.
The `import()` call, commonly called _dynamic import_, is a function-like expression that allows loading an ECMAScript module asynchronously and dynamically into a potentially non-module environment.

Unlike the [declaration-style counterpart](/en-US/docs/Web/JavaScript/Reference/Statements/import), dynamic imports are only evaluated when needed, and permits greater syntactic flexibility.

Josh-Cena marked this conversation as resolved.
Show resolved Hide resolved
## Syntax

```js
import(moduleName)
```

The `import()` call is a syntax that closely resembles a function call, but `import` itself is a keyword, not a function. You cannot alias it like `const myImport = import`, which will throw a `SyntaxError`.
The `import()` call is a syntax that closely resembles a function call, but `import` itself is a keyword, not a function. You cannot alias it like `const myImport = import`, which will throw a {{jsxref("SyntaxError")}}.

### Parameters

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ used in embedded scripts unless such script has a `type="module"`. Bindings
imported are called live bindings because they are updated by the module that exported
the binding.

There is also a function-like dynamic [**`import()`**](/en-US/docs/Web/JavaScript/Reference/Operators/import), which does not require scripts of `type="module"`.
There is also a function-like dynamic [`import()`](/en-US/docs/Web/JavaScript/Reference/Operators/import), which does not require scripts of `type="module"`.

Backward compatibility can be ensured using attribute `nomodule` on the
{{HTMLElement("script")}} tag.
Expand Down