Drenai
Drenai

Reputation: 12367

Angular JIT & AOT in memory factory classes - are they actually generated or just in-memory?

Using the Angular CLI, with the default ng new app, I created a JIT and an AOT project to compare file sizes, bundling, inspect in Chrome DevTools etc.

I then served both of these, and inspected the files in Chrome DevTools - JIT: ng serve - AOT: ng serve --aot

For the JIT version, the ngFactory files have all be compiled by the JIT compiler (for AOT, these exact functions are in the pre-compiled main bundle).

The documentation says that the ng class factories are created in memory in the JIT version of the app

JIT compilation generates these same NgFactories in memory where they are largely invisible.

When I veiw the JIT app in DevTools, (see screenshot) I can see the JIT compiled factory files under no domain. Are these actually in-memory, or does the compiler generate temporary files, or what??

enter image description here

Upvotes: 2

Views: 202

Answers (1)

yurzui
yurzui

Reputation: 214175

They are in browser memory when you're running JIT compilation.

Angular generates them through new Function()

For example:

var expression = `
    function Yurzui() {
      this.param1 = name;
    }
    Yurzui.prototype.hello = function() {
      return 'Hello ' + this.param1;
    }
    return Yurzui;
    //# sourceURL=/yurzui/say-hello/my.factory.js
`;

var func = new Function('name', expression);

var clazz = func('Some name');
alert((new clazz()).hello());

Plunker Example

enter image description here

Upvotes: 3

Related Questions