Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Intent to ship: Dynamic module imports (JS 'import()' syntax)

159 views
Skip to first unread message

Jon Coppeard

unread,
Mar 7, 2019, 6:30:01 AM3/7/19
to
I intend to enable dynamic module import on by default, to ship in Firefox 67. It has been developed behind the javascript.options.dynamicImport preference. This is already shipping in Chrome, Safari and Opera.

Bug to turn on by default: https://bugzilla.mozilla.org/show_bug.cgi?id=1517546

This feature was previously discussed in this "intent to implement" thread:

https://groups.google.com/forum/#!searchin/mozilla.dev.platform/dynamic$20import%7Csort:date/mozilla.dev.platform/8xmgmr9wJhc/NfX34H9KBQAJ

Jon

rek...@gmail.com

unread,
Mar 7, 2019, 6:14:50 PM3/7/19
to
Is there any way to feature detect support for import() syntax?

Boris Zbarsky

unread,
Mar 7, 2019, 9:52:40 PM3/7/19
to
On 3/7/19 6:14 PM, rek...@gmail.com wrote:
> Is there any way to feature detect support for import() syntax?

In Firefox, yes, as far as I can tell:

try {
new Function("import('')");
// supported
} catch (e) {
// not supported
}

-Boris

Martin Thomson

unread,
Mar 7, 2019, 10:27:47 PM3/7/19
to Boris Zbarsky, dev-platform
Is there a way that doesn't rely on eval or eval-like mechanisms?
> _______________________________________________
> dev-platform mailing list
> dev-pl...@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>

Boris Zbarsky

unread,
Mar 7, 2019, 10:38:21 PM3/7/19
to
On 3/7/19 10:27 PM, Martin Thomson wrote:
> Is there a way that doesn't rely on eval or eval-like mechanisms?

I suspect the only detectable thing here (and Jon might wake up tomorrow
and tell me I'm wrong!) is that import('stuff') is a syntax error
without the support but is not a syntax error otherwise.

That means you need to trigger at least a new parse of some JS that you
control to run the detection.

Now you could probably manage this with something like (using non-inline
scripts for all this stuff):

<script>
var oldError = window.onerror;
window.onerror = function(...args) {
/* check for syntax error */
}
</script>
<script>function() { import(''); }</script>
<script>window.onerror = oldError;</script>

or so.

-Boris

Martin Thomson

unread,
Mar 7, 2019, 11:28:47 PM3/7/19
to Boris Zbarsky, dev-platform
Thanks. (And ugh, but that's how these things go.)
0 new messages