Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Would anyone who already knows this tool, or is taking the time to learn it, care to explain what they mean by "compiles web apps down into compact, high-performance JavaScript"? I assume this is a JS-to-JS translator. How exactly are they transforming the JS?

I mean, of course, besides the obvious things they mention: minification, removing dead code, and some error checking.



Take a look here: http://code.google.com/closure/compiler/docs/api-tutorial3.h...

When you turn on advanced mode they do automatic inlining, variable substitution, and they don't respect the globalness of anything unless you specifically force something to be global.

YUI Compressor assumes anything not in a function is global, so it won't rename top level objects. Closure in advanced mode will trample through your globals and property names like rhinos mating in a field of daises.


I get concerned that these minimisers and js to js compilers will introduce subtle bugs and changes into the behaviour of my code. Is that concern warranted?


Closure advanced mode will absolutely screw with your code.

Closure simple mode and YUI Compressor won't change the behavior of your code. They just rename completely encapsulated objects with shorter names and remove unnecessary semicolons.


This is one of the things I've been wondering about. I'd like to look at ways to get Closure to be more holistic in it's approach.

YUI Compressor has always been safe. I think the concern I have is that the new, exciting features here are the unsafe ones and, obviously, those are the ones that are dangerous.

I'd be really interested in seeing how we can make features like this safe again. For example, by scraping a page, rather than just a JavaScript file to see which methods are genuinely unused instead of those unused in an undefined context of an unlinked JS file.


If the Closure "compiler" changes the behavior of a program, that means it's generating incorrect code. Can you give an example?


Check out http://code.google.com/closure/compiler/docs/api-tutorial3.h...

(short version: inconsistencies between Closure renaming my_object.attribute to a minified a.a while in other places you use my_object['attribute'] which it can't minify to be a.a. You end up with a.a = 3 and a['attribute'] = {something else}).


Ah. This is a classic problem with transforming JS. We've run into something similar with Parenscript (but were able to correct it, rather than say "just don't write code that does X").




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: