ClojureScript {:optimizations :advanced}

257 views
Skip to first unread message

Thomas Heller

unread,
Feb 5, 2012, 11:39:19 AM2/5/12
to clo...@googlegroups.com
Hey,

I'm starting to get the hang of Clojure(Script) and I'm really enjoying it. I'd love to use it for a project but I have one major concern: How reliable is {:optimizations :advanced}?

Advanced Compilation basically wins the whole argument for clojurescript but I managed to break it on a very simple project. I assume it broke because I tried to use jQuery and didnt stick to the closure library. The only reason I wanted to jQuery is because I'm very familiar with it (and javascript itself for that matter) and basically know nothing about closure, but I did some (rtfm closure) and managed to get it working without jQuery. Turns out you really dont need it.

So is it a fair assumption that as long as I stick to Closure Library + any ClojureScript itself I'm good on the :advanced part? I'm not interested in node.js as a :target, only the Browser. Falling back to {:optimizations :simple} really is not an option since the resulting javascript is way too big.

Cheers,
/thomas

PS:

My Experiments with jQuery:

The App is pointless and only tested in Chrome (firefox/ie dont like input[type='range']) but it should update the the input when you move the slider and update the slider when you change the input. dev/simple work fine, advanced breaks with some undebuggable error. I assume because the compiler optimized something away.

The Closure Version:

Basically the same amount of code, so no reason to use jQuery. But I'd still be interested to know why the jQuery version breaks.

Mark Rathwell

unread,
Feb 6, 2012, 1:56:14 PM2/6/12
to clo...@googlegroups.com
In short, yes, if you stick to gClosure, advanced compilation will
work fine. Closure advanced compilation is an optimizing compilation
that minifies names and removes dead (unused, uncalled) code. Trying
to use jQuery without special effort will result in calls to jQuery
being unaddressable. There is a nice writeup on including external
javascript with ClojureScript and the Closure compiler at [1]. Also,
jayq has an externs file for advanced compilation with jQuery 1.7 at
[2].

[1] http://lukevanderhart.com/2011/09/30/using-javascript-and-clojurescript.html
[2] https://github.com/ibdknox/jayq/blob/master/resources/externs/jquery.js

> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clo...@googlegroups.com
> Note that posts from new members are moderated - please be patient with your
> first post.
> To unsubscribe from this group, send email to
> clojure+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

David Nolen

unread,
Feb 6, 2012, 2:10:18 PM2/6/12
to clo...@googlegroups.com
More externs files here:

http://code.google.com/p/closure-compiler/source/browse/#svn%2Ftrunk%2Fcontrib%2Fexterns

I imagine that the CJLS community will provide something similar for useful, popular JavaScript libraries not covered well by CLJS, Closure, or CLJS libs. 

David
Reply all
Reply to author
Forward
0 new messages