Google Closure Compiler: a whole-world optimizer for JavaScript, not a general minifier
A JavaScript checker and optimizer.
At a glance
- What is it?
- Closure Compiler parses JavaScript, checks types and references, and rewrites what is left. Its ADVANCED mode is where the value is, and it is also where the constraints live.
- Who is it for?
- Adopt Closure Compiler if you own the entire JavaScript that ships, you can annotate it with JSDoc types, and you accept goog.module() as your module system. Do not adopt it as a drop-in minifier for third-party bundles, for NodeJS services, or for an ECMAScript module codebase, because the README states that non-ADVANCED modes are deprecated, NodeJS support never worked very well, and ESM support is not actively maintained.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository received new commits within the last day.
- What is it written in?
- Mainly JavaScript, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on November 14, 2026, and from our analysis. They are not legal advice.
Star history
- google/closure-compiler7,705 ★ · +19
| Repository | 2026-09-22 | 2026-11-14 |
|---|---|---|
| google/closure-compiler | 7.7k | 7.7k |
19 Stars in the last 53 days, measured from the daily GitHub snapshot. Compare with other projects
Editorial analysis
What Closure Compiler actually solves, and for whom
The README describes the tool as a true compiler for JavaScript: it compiles from JavaScript to better JavaScript, parses the source, analyzes it, removes dead code, and rewrites and minimizes what remains. It also checks syntax, variable references, and types, and warns about common JavaScript pitfalls. The intended beneficiary is a team shipping a very large JavaScript application, where the README lists the goals as drastically reducing code size, checking code for errors and project-specific best practices, defining localizable user-visible messages, transpiling newer features for older browsers, and splitting output into chunks that load on demand.
Read the caveats before the feature list. The README states that compilation modes other than ADVANCED were always an afterthought and are now deprecated, because other tools perform comparably for non-ADVANCED modes and are better integrated into the broader JS ecosystem. So the honest framing is narrow: this is an ADVANCED-mode optimizer, and everything else it does is a side effect of that mode. If you want a minifier with a friendly default, this is not it.
The whole-world model: why property renaming breaks hidden names
Closure Compiler is a whole-world optimizer. The README says it expects to directly see, or at least receive information about, every possible use of every global or exported variable and every property name, and it will aggressively remove and rename variables and properties to shrink output. Anything hidden from it produces broken JavaScript.
The concrete rule is about property access style. The compiler requires you to access a property consistently with either obj[p] or obj.propName, never both. Bracket access, or destructuring like let {p} = obj;, hides the literal name from the compiler, which then cannot tell whether obj.propName refers to the same property. Sometimes it detects the conflict and stops with an error. Other times, per the README, it renames propName to something shorter without noticing, and the output is broken. The same class of failure applies to inlining of globals and flattening of property chains such as myFoo.some.sub.property into myFoo$some$sub$property: the compiler tries to back off or halt, but the README concedes there are cases where it fails to recognize the problem and emits broken JavaScript without warning, and that this is much more likely in code not written with the compiler in mind.
That is the trade-off in one sentence: the compiler buys size by assuming total visibility, and every boundary you cannot show it becomes a runtime bug.
Installing it and running a first ADVANCED compilation
The repository is built with Bazel (the top level holds BUILD.bazel, MODULE.bazel and a .bazelversion file), and package.json exposes a single script that runs the deployed jar. The README links to the project page at developers.google.com/closure/compiler/, so treat the command below as the repository's own build path rather than a published install guide.
From a checkout, the package script invokes the jar produced by the Bazel build:
npm run compileThat resolves to java -jar bazel-bin/compiler_uberjar_deploy.jar, so the jar has to exist first. The repository has no published releases, so verify the artifact source before wiring this into a build.
Read the README's Getting Started section and the project page before choosing flags, and check the output for properties that your runtime looks up by string. If your code reads a property name from a JSON payload or a data attribute while the same property is also touched with dot access somewhere, ADVANCED mode may have renamed the declaration while the string lookup stayed as it was. The README's own workaround is a custom externs file that tells the compiler to leave certain names unchanged, and it adds that maintaining those files is often tedious.
Where ADVANCED mode is the wrong tool
The README is unusually direct: Closure Compiler is not suitable for arbitrary JavaScript, and for ADVANCED mode to generate working JavaScript, the input must be written with closure-compiler in mind. That single sentence disqualifies a large set of plausible uses.
The module system is the second wall. JavaScript that does not use goog.module() and goog.require() from base.js to declare and use modules is not well supported. ECMAScript import and export syntax is implemented to some degree, but the README states that Google's TypeScript is converted to goog.module() before the compiler sees it, so ESM support is effectively unused inside Google, which means bugs in it are unlikely to be noticed or fixed. CommonJS input was added in the past, is not used internally, and the README says it is likely to be entirely removed.
The environment assumption is the third. The compiler and its default externs assume a browser window. WebWorkers are supported, but the README warns the compiler will likely fail to warn you when you use features a WebWorker does not actually have. Some externs and features exist for NodeJS, but the README says they are not actively supported and never worked very well. If you are bundling a server-side Node application, the type checking may still be useful, but the size optimization is built for a different target.
Closure Compiler compared with Terser and webpack
The difference is scope of knowledge, not output size. Terser is a minifier: it works on a file or a bundle as given, renames local variables, and does not need to know anything about how your code is used elsewhere. webpack is a bundler that resolves modules and produces assets, with minification delegated to a tool like Terser. Neither requires you to restructure property access or adopt a particular module syntax.
Closure Compiler in ADVANCED mode does require those things, and in exchange it reasons across the whole program: it removes code it can prove is unused, inlines globals, flattens property chains, and renames properties, which a per-file minifier cannot safely do. The README's own position is that for non-ADVANCED modes other tools are comparable and better integrated, so the comparison is not "Closure versus Terser at minification". It is "do you control every use of every global and property, or not". If you do, ADVANCED mode reaches sizes a minifier cannot. If you do not, Terser or webpack will produce working output where Closure Compiler may silently produce broken output.
Maintenance cost, licence, and what a build pipeline inherits
The repository is not archived, and the last push was on 2026-11-02, so the codebase is moving. That does not change the support matrix in the README, which is explicit about which paths are maintained and which are not. ESM support is described as effectively unused internally, CommonJS input is slated for likely removal, and NodeJS externs are described as never having worked very well. A long-lived build that depends on any of those three inherits that risk regardless of commit activity.
The practical cost is externs maintenance. Every boundary where code outside the compilation touches a renamed global or property needs an externs entry, and the README calls this often tedious. Budget for it as ongoing work, not a one-time setup.
The project is Apache-2.0. That is a permissive licence, and the repository ships a LICENSE file and a THIRD_PARTY_NOTICES file, which is what you would expect for a project that bundles dependencies. Whether the notices impose anything on your distribution is a question for your own legal review, not something this article can settle.
Frequently asked questions
Common questions about using Closure Compiler and how its documented caveats answer them.
Editorial conclusion
Adopt Closure Compiler if you own the entire JavaScript that ships, you can annotate it with JSDoc types, and you accept goog.module() as your module system. Do not adopt it as a drop-in minifier for third-party bundles, for NodeJS services, or for an ECMAScript module codebase, because the README states that non-ADVANCED modes are deprecated, NodeJS support never worked very well, and ESM support is not actively maintained. Before committing, compile one real entry point with ADVANCED and inspect the output for renamed properties that your runtime looks up by string.
Frequently asked questions
How do I use Google Closure Compiler?
Point it at JavaScript written for it, run it in ADVANCED mode, and check the output for renamed properties that your runtime looks up by string. The README states that for ADVANCED mode to produce working JavaScript, the input must be written with closure-compiler in mind.
What is Google Closure Compiler?
It is a JavaScript checker and optimizer described in the README as a true compiler for JavaScript: it compiles from JavaScript to better JavaScript, parsing, analyzing, removing dead code, and rewriting and minimizing what remains.
Closure Compiler vs webpack: what is the difference?
The README says that compilation modes other than ADVANCED are deprecated because other tools perform comparably there and are better integrated into the broader JS ecosystem, which places the distinction at ADVANCED mode's whole-world renaming and dead code removal.
Google Closure Compiler vs Terser: which should I pick?
The README states that for non-ADVANCED modes other tools are comparable and better integrated, so the reason to pick Closure Compiler is ADVANCED mode, which requires input written with the compiler in mind and consistent property access.
What are Closure Compiler alternatives?
The README says that for modes other than ADVANCED, other tools perform comparably and are better integrated into the broader JS ecosystem, which is the project's own statement about when another tool is the reasonable choice.
Official sources
Where developers are discussing it
Posts on Hacker News, dev.to and Lobsters that link to this repository, found by our scan of those communities. 0 in the last 30 days; newest first.
- Closure Compiler: A JavaScript checker and optimizerHacker News · Sep 14, 2026 · 3 points · 0 comments
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/google-closure-compiler)Star history chart for your README
[](https://hysenlabs.com/projects/google-closure-compiler)Was this useful?