0

I've got compiled a lib using emscripten, generating mylib.js.

Basically its interface is declared at the end of mylib.js:

var MyLib = function () {
  that = {};
  that.ptr = MyLib_constructor();
  that.destroy = function () {
    MyLib_destructor(that.ptr);
  };
  that.doSomething = function () {
    MyLib_doSomething(that.ptr);
  };
  return that;
};

I'm integrating it in an HTML page like this:

<html>
<head>
  <script src="mylib.js"></script>
</head>
<body>
  <script>
    var MyLibInstance = MyLib();
    /*...*/
  </script>
</body>
</html>

However in the console I've got the following warning:

Successfully compiled asm.js code (total compilation time 17ms; unable to cache asm.js in synchronous scripts; try loading asm.js via or createElement('script'))

1. Does this impact performance? How?

I then try to make the script call async:

<script src="mylib.js" async=true></script>

Then it's OK for the cache:

Successfully compiled asm.js code (loaded from cache in 48ms)

But then MyLib is not found anymore:

ReferenceError: MyLib is not defined [Learn More]

2. Is there an example on how to make this code async and have the interface visible to my script?

moala
  • 5,094
  • 9
  • 45
  • 66
  • 1
    You have to wait for the script tag to finish loading (attach an event handler for the `load` event or `onload` property). Also take a look at emscripten's shell file command line parameter. – Jared Smith Apr 13 '17 at 17:43
  • Possible duplicate of [trying to fire onload event on script tag](http://stackoverflow.com/questions/16230886/trying-to-fire-onload-event-on-script-tag) – Jared Smith Apr 13 '17 at 17:47

0 Answers0