Skip to content

Compiling with Optimizations None

Bill La Forge edited this page Feb 19, 2016 · 2 revisions

Compiling with optimizations none is no doubt quite handy, especially in conjunction with source maps, as a traceback will take you to the line of code causing the problems, and with the same variable names used in your original clojurescript code. But this is not currently possible for .jc files used by web workers as the unoptimized .js file contains a reference to js/window--and window does not exist in a web worker.

You should still be able to use optimizations none with your main javascript code, but you will need to compile your main code and your web worker code separately so that you can use different optimizations as appropriate. And you can do this so long as your not using shared workers. The question then is, how to compile the .js files separately.

The duracell demo uses a web worker AND is itself compiled with optimizations none. There are two things done to accomplish this:

  1. Duracell itself has no web worker code. Though it uses a library, durable-cells, which includes a web worker.
  2. In the duracell build.boot file, the dev task uses pandeiro/boot-http rather than the simpler tailrecursion/boot-jetty. The advantage to using boot-http is that it supports the loading of static files from library jar files. In this case, that means the main code in aaworker can create a web worker using durable-cell's dcells.js file.

So how does the durable-cells library create the dcells.js file? Again, there are two things done to accomplish this:

  1. In the durable-cells build.boot file, the dev task includes (cljs :optimizations :simple). This invokes the compiler with an appropriate level of optimizations.
  2. But we still need to define the .js file. This is done in the dcells.cljs.edn file. See Multiple Builds for more information on cljs.edn files.
Clone this wiki locally