-
Notifications
You must be signed in to change notification settings - Fork 40
Namespace pollution
By default, the Google Closure compiler and, by extension, the ClojureScript compiler assume that they control the global Javascript namespace. When using external JavaScript libraries in conjunction with :optimizations simple
or :optimizations :advanced
, this can cause problems, as the short names the compiler chooses for JavaScript functions often collide with those used in JavaScript libraries.
For example, with advanced optimizations, Closure picks two-letter combinations like window.fb
and window.dt
, clobbering functions defined in popular frameworks. This results in hard-to-trace JavaScript errors. What's more, these problems can appear seemingly out of the blue as the result of unrelated changes which accidentally affect Closure's naming scheme.
When working with boot-cljs, the solution is to set the :output-wrapper
compiler option to true
. For example, your main.edn
may look like this:
{:require [app.core]
:init-fns [app.core/main]
:compiler-options {:optimizations :advanced
:output-wrapper true}}
See the Google Closure FAQ item and the ClojureScript wiki for more details.
Note that currently :output-wrapper true
cannot be used with :optimizations :whitespace
(ticket).