How to Use ES Modules in Modern Browsers: Compatibility and Tips
This article explains which browsers currently support ES modules, how to enable them, the rules for module import paths, using nomodule for fallback, the default defer behavior of module scripts, and the execution order of inline and external module scripts.
Browsers have begun supporting ES modules, and you can try them in the following browsers:
Safari 10.1
Chrome Canary 60 – enable experimental mode in chrome:flags
Firefox 54 – set dom.moduleScripts.enabled in about:config
Edge 15 – enable experimental mode in about:flags
You only need to add
type=moduleto a
scripttag, and the browser will treat the inline or external script as an ECMAScript module. Although there are good articles about JavaScript modules, I want to share some browser‑specific module features.
Shortened import paths will not be supported
A valid module path must satisfy one of the following conditions:
Full URL address (non‑relative URL)
Starts with
/.Starts with
./.Starts with
../.(other specifiers are reserved for future use, such as importing a built‑in browser module)
nomodule can be used for fallback
If a browser supports
type=module, it will ignore
scripttags with the
nomoduleattribute, allowing you to provide a fallback for browsers that do not support ECMAScript modules.
Default Defer
The loading order is
2.js,
1.js,
3.js. Regular scripts block page rendering during loading; you can use
deferto avoid this, which delays execution until the document is parsed while preserving order. Module scripts are
deferby default, so they do not block HTML parsing.
Inline module scripts are also deferred
The execution order will be:
1.js, inline script, inline module,
2.js. Regular inline scripts ignore defer, whereas inline module scripts are always deferred, regardless of whether they import anything.
Tencent IMWeb Frontend Team
IMWeb Frontend Community gathering frontend development enthusiasts. Follow us for refined live courses by top experts, cutting‑edge technical posts, and to sharpen your frontend skills.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.