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

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
0
Jon
3/7/2019 11:29:59 AM
mozilla.dev.platform 6516 articles. 0 followers. Post Follow

5 Replies
32 Views

Similar Articles

[PageSpeed] 32

Is there any way to feature detect support for import() syntax?
0
rektide
3/7/2019 11:14:48 PM
On 3/7/19 6:14 PM, rektide@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
0
Boris
3/8/2019 2:52:34 AM
Is there a way that doesn't rely on eval or eval-like mechanisms?

On Fri, Mar 8, 2019 at 1:55 PM Boris Zbarsky <bzbarsky@mit.edu> wrote:

> On 3/7/19 6:14 PM, rektide@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
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
0
Martin
3/8/2019 3:27:29 AM
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
0
Boris
3/8/2019 3:38:15 AM
Thanks.  (And ugh, but that's how these things go.)

On Fri, Mar 8, 2019 at 2:40 PM Boris Zbarsky <bzbarsky@mit.edu> wrote:

> 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
> _______________________________________________
> dev-platform mailing list
> dev-platform@lists.mozilla.org
> https://lists.mozilla.org/listinfo/dev-platform
>
0
Martin
3/8/2019 4:28:30 AM
Reply: