Questions tagged [google-closure-compiler]

Google Closure Compiler compiles a typed superset of modern JavaScript to a target version of JavaScript, applying type checking, dead code elimination, minification and other improvements.

The Closure Compiler is a tool for making JavaScript download and run faster. It is a true compiler for JavaScript. Instead of compiling from a source language to machine code, it compiles from JavaScript to better JavaScript. It parses your JavaScript, analyzes it, removes dead code and rewrites and minimizes what's left. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls.

The Closure Compiler has three optimization modes: whitespace only, simple optimizations, and advanced optimizations. The first two are safe for all JavaScript. The latter one imposes restrictions on JavaScript usage, but it is where Closure Compiler shines and the valuable type checking, dead code removal, and better minification.

1178 questions
183
votes
6 answers

How to indicate param is optional using inline JSDoc?

According to the JSDoc wiki for @param you can indicate a @param is optional using /** @param {String} [name] */ function getPerson(name) { } and you can indicate a param inline using function getPerson(/**String*/ name) { } And I can…
studgeek
  • 14,272
  • 6
  • 84
  • 96
154
votes
5 answers

How to document a string type in jsdoc with limited possible values

I am having a function that accepts one string parameter. This parameter can have only one of a few defined possible values. What is the best way to document the same? Should shapeType be defined as enum or TypeDef or something…
97
votes
6 answers

Running a command in a Grunt Task

I'm using Grunt (task-based command line build tool for JavaScript projects) in my project. I've created a custom tag and I am wondering if it is possible to run a command into it. To clarify, I'm trying to use Closure Templates and "the task"…
65
votes
4 answers

difference between "void 0 " and "undefined"

I'm using "Closure Compiler", when compiling my scripts I spend the following: Before compiling: // ==ClosureCompiler== // @compilation_level SIMPLE_OPTIMIZATIONS // @output_file_name default.js // @formatting pretty_print,print_input_delimiter //…
andres descalzo
  • 14,887
  • 13
  • 64
  • 115
64
votes
4 answers

Does it make sense to minify code used in NodeJS?

I was wondering, since Clojure Compiler and UglifyJS not only optimize code for size but also for performance (although I think size is the main priority), would my node.js app run faster if it was minified ? I know it may depend from app, but I'm…
62
votes
3 answers

What is the purpose of passing arguments to anonymous functions in this manner?

Possible Duplicate: How do JavaScript closures work? I was playing around with the Google Closure Compiler, putting in random code to see what it would do. It rewrote one of my functions to look something like this: (function(msg) {…
Kyle Macey
  • 8,074
  • 2
  • 38
  • 78
53
votes
7 answers

Should I use the YUI Compressor or the new Google Closure compiler to compress my JavaScript?

YUI Compressor was the consensus best tool for minimizing, but Closure seems like it could be better.
47
votes
5 answers

How to document CoffeeScript source code with JSDoc?

I have some code written in CoffeeScript and I want to optimize the generated JavaScript with the Google Closure Compiler, so these files need to be documented with JSDoc. My question is, how can I document the *.coffee files to generate javascript…
aztack
  • 4,376
  • 5
  • 32
  • 50
47
votes
12 answers

Exclude debug JavaScript code during minification

I'm looking into different ways to minify my JavaScript code including the regular JSMin, Packer, and YUI solutions. I'm really interested in the new Google Closure Compiler, as it looks exceptionally powerful. I noticed that Dean Edwards packer has…
Tauren
  • 26,795
  • 42
  • 131
  • 167
39
votes
10 answers

jQuery compiled with Google Closure Compiler

Has anyone compiled jQuery against Google's newly-released Closure compiler? There has been reported huge savings in code size. I'm curious what the benefit is if jQuery was compiled with it.
Ted
  • 555
  • 2
  • 5
  • 5
38
votes
8 answers

Google Closure Compiler with jQuery applications

I have a lot of time invested in jquery and a large application built with it. Recently I've been reviewing Google Closure Library, but at this time have found it to be not nearly as elegant as jquery. I believe it may have some potential and will…
Tauren
  • 26,795
  • 42
  • 131
  • 167
34
votes
5 answers

How to force google closure compiler to keep "use strict"; in the compiled js code?

If you're using the module pattern and have something like this: (function () { "use strict"; // this function is strict... }()); and compile the code using the Google Closure Compiler, the "use strict"; directive will not make it into the…
ivo
  • 4,101
  • 5
  • 33
  • 42
33
votes
1 answer

Chrome: Add local JavaScript SourceMap possible?

Is it possible to add a local SourceMap? I have a Website, which I cannot modify, containing compressed (closure) JavaScript. I have a local JavaScript-SourceMap belonging to that file. Is there any way to tell GoogleChrome (or any other browser) to…
agrafix
  • 765
  • 1
  • 5
  • 15
30
votes
3 answers

Does Google Closure Compiler ever decrease performance?

I'm writing a Google Chrome extension. As the JavaScript files are loaded from disk, their size barely matters. I've been using Google Closure Compiler anyway, because apparently it can make performance optimizations as well as reducing code…
callum
  • 34,206
  • 35
  • 106
  • 163
28
votes
2 answers

Play Framework 2: JavaScript gets duplicated as a result of minification (google closure compiler)

I have a weird issue related to JavaScript minification, the problem is that when placing JavaScript files such as test1.js, test2.js inside /assets/javascript/test folder and using following options for closure compiler: val defaultOptions = new…
1
2 3
78 79