JS source code is compiled to native code with the tool
nwjc , which is provided in the SDK build.
To use it:
nwjc source.js binary.bin
*.bin file is needed to be distributed with your application. You can name it whatever you want.
If you are compiling a module,
--nw-module argument is needed.
The arguments of the win.evalNWBin() method are similar with the
Window.eval()method, where the first parameter is the target iframe (
nullfor main frame), and the 2nd parameter is the binary code file.
If you are loading binary for modules, win.evalNWBinModule() should be used instead.
Use in Web Workers
importNWBin(ArrayBuffer) is introduced in worker context. The binary file can be read to array buffer in the main thread, posted to worker and then executed there with the new function.
Before 0.22, the compiled code runs slower than normal JS: ~30% performance according to v8bench. Other non-compiled JS source code will not be affected. In 0.22.0-beta1, this issue has been fixed. Please check our blog post: https://nwjs.io/blog/js-src-protect-perf/
The compiled code is not cross-platform nor compatible between versions of NW.js. So you’ll need to run
nwjc for each of the platforms when you package your application.