Live data from Hacker News

Closure Compiler: a tool for making JavaScript download and run faster

developers.google.com

21–30 of 77 posts

Re: Closure Compiler: a tool for making JavaScript download and run faster

#22
post #16
post #13

Earlier quoted context omitted.

Have a look at the advanced compilation option: https://developers.google.com/closure/compiler/docs/api-tuto... Basically when enabled it will rewrite normal property access, e.g: `myObj.foo` to something like `a.b` but wont shorten string literal access, e.g `myObj['foo']` just becomes `a.foo` which you would use for any API's you want to export. For a real-world example I use string literals for declaring jquip's p…

May i ask why you are using this notation? I honestly can't think of any benefits. Isn't it more convenient and readable to use `p.removeAttr`?

My comment explains the entire purpose for using it - if I didn't, it would've got rewritten into `a.b` and none of the public API's would work!

Re: Closure Compiler: a tool for making JavaScript download and run faster

#23
post #22
post #16

Earlier quoted context omitted.

May i ask why you are using this notation? I honestly can't think of any benefits. Isn't it more convenient and readable to use `p.removeAttr`?

My comment explains the entire purpose for using it - if I didn't, it would've got rewritten into `a.b` and none of the public API's would work!

I wish there were a better way to indicate which properties were renameable, because I need this too and I'm not willing to go as far as you did.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#24
Google Closure is not only a useful tool at the command line, it's also an incredibly powerful framework for manipulating, analyzing, checking, and producing JavaScript in a dizzying number of ways. And now thanks to Java 8's Nashorn you can skip the Java and script it quite productively with JS, https://gist.github.com/swannodette/aad077de18309a08cff3

Re: Closure Compiler: a tool for making JavaScript download and run faster

#25
post #13
post #2

How can it determine dead code for such a dynamic language like JavaScript? Is it limited to obvious stuff like things after a "return;" statement that cannot run? Because I don't see how it could remove unused functions when you can invoke them in such indirect ways: myobj['f'+'oo']();

Have a look at the advanced compilation option: https://developers.google.com/closure/compiler/docs/api-tuto... Basically when enabled it will rewrite normal property access, e.g: `myObj.foo` to something like `a.b` but wont shorten string literal access, e.g `myObj['foo']` just becomes `a.foo` which you would use for any API's you want to export. For a real-world example I use string literals for declaring jquip's p…

How did it know it could leave out the `this.nodeType` check?

Re: Closure Compiler: a tool for making JavaScript download and run faster

#27
post #22

Earlier quoted context omitted.

My comment explains the entire purpose for using it - if I didn't, it would've got rewritten into `a.b` and none of the public API's would work!

I wish there were a better way to indicate which properties were renameable, because I need this too and I'm not willing to go as far as you did.

there is a much better way to deal with this:

https://developers.google.com/closure/compiler/docs/api-tuto...

Re: Closure Compiler: a tool for making JavaScript download and run faster

#28

Why is the closure library not as popular as other alternatives (ex: jquery)? It looks like a solid library, used by gmail, google docs and other google apps, I'm guessing is the java requirement for the compiler.

You can't write regular code to take advantage of its advanced features- It requires you to program in a strict subset of regular javascript, and that is a bit of a PITA.

Re: Closure Compiler: a tool for making JavaScript download and run faster

#29
post #22

Earlier quoted context omitted.

My comment explains the entire purpose for using it - if I didn't, it would've got rewritten into `a.b` and none of the public API's would work!

I wish there were a better way to indicate which properties were renameable, because I need this too and I'm not willing to go as far as you did.

You can tell it which properties to keep with `goog.exportSymbol()`

Re: Closure Compiler: a tool for making JavaScript download and run faster

#30
post #8

Earlier quoted context omitted.

I think it's likely that long-term, the approach FB took with Flow (or more general Abstract Interpretation methods) should be able to handle more cases with less effort on the developer's side (albeit with increased computational costs). The modules/"code motion" is a bit strange at first glance, but definitely a huge boon for building debuggers/admin interfaces/etc. that you don't want included in your main applica…

It's not clear what you're referring to wrt. "the approach FB took with Flow" and Abstract Interpretation. Type checking? Dead code elimination? In anycase, Google Closure Compiler also leverages Abstract Interpretation.

Thanks for pointing out the ambiguity.

Closure would probably be the most interesting (or close to the most interesting) project to work on inside of Google-proper, for me personally. That said, Google's approach is very much on the opposite side of FB's, in that Google expects the vast majority of code to be written for it. FB is dealing with a legacy codebase and has fewer engineers, so has to strike a different set of tradeoffs - less up-front work to integrate their tooling for potentially less benefit than something like Closure can deliver. It's interesting to see the two different approaches.

Anyway, this thread is about Closure, which enables ClojureScript, which is my go to language these days. The developers working on the compiler and the stdlib (which is amazing) should feel proud about all the people they've enabled.

Post reply on HN