Dart Separation

Is there any way to split the code in Darth? I would like to postpone the loading of some rarely used code in order to speed up the loading of the source code. In Javascript, I would add a new <script> , in GWT I would just call GWT.runAsync() . Is there something similar in Darth?

According to this link , <script> injection will not work ("Each HTML page can contain no more than one Dart script tag," "We do not support the dynamic injection of a tag that loads the Dart code."). I also found this fixed problem by stating: "The initial [use case] is delayed loading to avoid bulk downloads when some code is needed only later or maybe only needed in some situations. We now have a mechanism for this." Unfortunately, I could not find anything about how to implement this. Does anyone know about this?

+6
source share
1 answer

September 2014 update: it is fixed!

Now Dart easily supports deferred loading using the special import... deferred syntax. For instance:

 import analytics.dart deferred as analytics void main(){ analytics.loadLibrary.then((_) { // future // code ready enableAnalyticsControl() }); } 

Here's the official tutorial on using lazy loading.


I'm afraid that what you are trying to do is still not possible (it is assumed that you are not using dart2js).

See this issue .

As Kasper said in comment 3, the deployment feature that you get with dart2dart has so far been discussed. The involvement of virtual machines in supporting this ends up giving dart2dart a generated access code for lazy downloads through a library call. This library API still needs to be specified.

If you use dart2js, this can be done. Here is a blog post on how to do this.

 const lazy = const DeferredLibrary('reverser', uri: './part.js'); 

Which allows you to call lazy.load().then((_) { ...

+7
source

Source: https://habr.com/ru/post/944291/


All Articles