2015-09-10 Async loaded figwheel cljs

As a part of developing ClojureScript widgets, I would like to be able to use figwheel development for code embedded in another site. The challenge is that the code is just loaded async from another url. This breaks the figwheel-setup as the relative paths does not work anymore, and scripts cannot be loaded with document.write("<``script ...>"); which closure uses for loading.

Because the script is loaded async, the following error occur:

Failed to execute 'write' on 'Document': It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

And the of course the figwheel source fails because, it has relative paths.

Essentially this can be solved, by rewriting the figwheel entry javascript code with the following changes:

  1. No use of document.write
  2. Set goog.ENABLE_CHROME_APP_SAFE_SCRIPT_LOADING to true, which has the effect that closure will not use document.write for loading scripts.
  3. Manually load goog/deps.js, that closure tries to load before document.write was disabled for loading scripts.

After these changes, it is possible to link to figwheel just async loading a single js-file, and have nice interactive cljs-widget development within another site 🙂

Actual code here.