bhauman / lein-figwheel

Figwheel builds your ClojureScript code and hot loads it into the browser as you are coding!
Eclipse Public License 1.0
2.88k stars 209 forks source link

document.write and Greasemonkey / Tampermonkey #589

Closed tosh closed 7 years ago

tosh commented 7 years ago

I am currently converting a Greasemonkey script from JavaScript to ClojureScript and have trouble to get a fighweel setup going for development mode.

I tried to use the Greasemonkey JavaScript to insert a script tag that points to figwheel's output. That worked (e.g. for optimized output where figwheel puts everything into one file) but in development mode figwheel's JavaScript output uses document.write calls to add the script tags it needs.

Since I do not control the backend of the websites I am working with I can only (asynchronously?) add a script tag to the page like this:

(function () {
    var scriptElement = document.createElement( "script" );
    scriptElement.type = "text/javascript";
    scriptElement.src = "https://127.0.0.1/js/compiled/out.js";
    document.body.appendChild( scriptElement );
})();

Unfortunately browsers then seem to block document.write calls in out.js (this is a StackOverflow question I found that seemed related: https://stackoverflow.com/questions/32261556/how-to-load-third-party-javascript-tag-asynchronously-which-has-document-write) So I was wondering if figwheel needs the document.write calls or if there would be another way?

bhauman commented 7 years ago

So in :optimizations none mode ClojureScript via google Closure has this behavior. If you are just getting strated with clojurescript I would try using lein cljsbuild with :optimizations :simple and just use a manual reload style of development. You can hack how things are loaded but I don't think you want to go down that road, as its pretty dang complex.