Skip to content

Optional Self hosting

David Nolen edited this page Aug 2, 2015 · 15 revisions

This page documents advice for people wanting to build ClojureScript projects that want or need to leverage cljs.js/eval-str and other self-hosted functionality.

WARNING: If you are building a web application where the final size of the deployed artifact matters significantly you should not be leveraging any of the functionality outlined on this page.

Production Builds

You can leverage :optimization :simple with builds that include the cljs.js namespace. Other recommended settings:

:pretty-print false
:optimize-constants true
:static-fns true

:optimize-constants is significant for cod size, all keys and symbols in your source will be compiled into a single lookup table.

By default for ease of use cljs.js/empty-state will dump the analysis cache for cljs.core. This doubles the size of the final file. You can disable this with setting :dump-core false in your compiler build options.

This means you will need to load the analysis for for yourself for example that might look something like this:

(def st (cljs.js/empty-state))

;; path to Transit encoded analysis cache
(def cache-url "/assets/js/cljs_next/cljs/core.cljs.cache.aot.json")

(defn main []
  (http/get cache-url
    (fn [json]
      (let [rdr   (transit/reader :json)
            cache (transit/read rdr json)]
        (cljs.js/load-analysis-cache! st 'cljs.core cache)
        ;; ...
        ))))
Clone this wiki locally