CopperLicht 1.3.0 released and why Google Closure sucks

I just released the JavaScript WebGL Library CopperLicht in version 1.3.0. It includes several new features and major changes, for example enhanced shader support (callbacks for shader variables), better debugging support, possibility to clone 3D meshes. But the major change is that the whole library is now included in it's own namespace, CL3D, which makes it easier to use it together with other libraries, for example jQuery.

In previous versions, CopperLicht was optimized and minificated using the Google Closure Compiler, shortening lots of function and variable names, and cluttering random new variables all over the global namespace. Since the Closure compiler is quite popular, other libraries usually do the same, and when two such libraries get included together in one website, the generated new global variable names usually collide. Which basically sucks. There are (painful) workarounds for this, but honestly, they were a pain in the ass.

Additionally, once I put CopperLicht into it's new namespace, the closure compiler totally stopped behaving: It would put out invalid warnings and strip out symbols. Especially after updating to the latest compiler versions: Instead of improving the compiler, the developers obviously decided to include lots and lots of random warnings into it. (Come on, you want to force your coding style on me? No thanks. I think I know where I want to use the 'this' keyword and where not myself.) Reading the user forums and documentation, it seems Google Closure now is not intended anymore to be used by library developers (if it was ever, but it worked before for me). It is only useful in this case: Write an application, include all your libraries, and run the compiler over all code together to produce the end result. This works perfectly with Google closure, and produces excellent results.

Of course this isn't nice for my use case. So I tried out the alternative, Yahoo's YUI compressor. And interestingly, this is exactly what I needed: The compressor simply renames local names to produce a javascript code wich still does exactly the same, without any side effects. Perfect for developing a library. Nicely, ycompressor also does this quite fast, since it doesn't really analyze any code in depth for this.

So summarized: I probably should have named this blog post "[...] and why Google Closure sucks for libraries" instead, because it still is a useful tool. There are a lot of Closure vs. YCompressor comparison articles on the web, probably they also should note that those two can be used for totally different areas as well.

five comments, already:

Somehow gives the impression you try unscrew with a hammer and complain that it doesn’t work alright, because you always break the screw…
xaos - 29 10 10 - 10:41

hm… how does a javascript compressor know what variables/methods should be renamed and what variables/methods should be left alone because they are part of an api?
horace () - 29 10 10 - 14:25

It probably only renames the local variables.
niko - 30 10 10 - 13:39

CL3D[‘function_name’] = function () {
...
}

Strings never get shortened.
Stani () (link) - 23 11 10 - 19:01

This got lost, first define:

var CL3D = window[‘CL3D’] = {}
Stani () (link) - 23 11 10 - 19:03


Name:  
Remember personal info?
yes
no
Email (optional):
URL (optional):
Enter "layered" (antispam):
Comment:Emoticons / Textile

  ( Register your username / Log in )

Notify: Yes, send me email when someone replies.  

Small print: All html tags except <b> and <i> will be removed from your comment. You can make links by just typing the url or mail-address.
Note: If you type in your email adress above, it will be visible to other visitors, although it will be hidden for bots using javaScript.