Skip to content

Namespace pollution

Paulus Esterhazy edited this page Dec 21, 2016 · 7 revisions

The Google Closure compiler assumes that it owns the global Javascript namespace. When using :optimizations simple or :optimizations :advanced, this can cause problems, as the names it 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 from popular frameworks. This results in hard-to-trace JavaScript errors. What's more, these problems can appear as the result of unrelated changes, which accidentally influence Closure's naming scheme.

For boot-cljs, the solution is to set the :output-wrapper true compiler option. A 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 for more details.

Note that currently :output-wrapper true cannot be used with :optimizations :whitespace (ticket).

Clone this wiki locally