Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9210265
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T01:01:48+00:00 2026-06-18T01:01:48+00:00

I want to use Closure Compiler to minify/compress JS code. the problem is that

  • 0

I want to use Closure Compiler to minify/compress JS code.

the problem is that it doesn’t minify as well as I expect it to. consider the code below. when I pass the string

var func = function ( someArgument ) {
  alert ( someArgument ); 
  return someArgument; 
}

I expect the minified code to rename “someArgument” to something much shorter, like “a”.

is that the way it is or am I doing something wrong? TIA

public static void Compress( String src ) {

    ByteArrayOutputStream err = new ByteArrayOutputStream();

    CompilerOptions opt = new CompilerOptions();

    CompilationLevel.ADVANCED_OPTIMIZATIONS.setDebugOptionsForCompilationLevel( opt );

    Compiler.setLoggingLevel( Level.OFF );
    Compiler compiler = new Compiler( new PrintStream( err ) );
    compiler.disableThreads();

    List<SourceFile> externs = Collections.emptyList();
    List<SourceFile> inputs = Arrays.asList( SourceFile.fromCode( "javascript-code.js", src) );

    Result result = compiler.compile( externs, inputs, opt );

    System.out.println( "source: " + compiler.toSource() );
}
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T01:01:50+00:00Added an answer on June 18, 2026 at 1:01 am

    You are using setDebugOptionsForCompilationLevel(), you want setOptionsForCompilationLevel(). From the Source this is what setDebugOptionsForCompilationLevel is doing:

    public void setDebugOptionsForCompilationLevel(CompilerOptions options) {
        options.anonymousFunctionNaming = AnonymousFunctionNamingPolicy.UNMAPPED;
        options.generatePseudoNames = true;
        options.removeClosureAsserts = false;
        // Don't shadow variables as it is too confusing.
        options.shadowVariables = false;
    }
    

    While this is what setOptionsForCompilationLevel() is doing:

    // All the safe optimizations.
    options.dependencyOptions.setDependencySorting(true);
    options.closurePass = true;
    options.foldConstants = true;
    options.coalesceVariableNames = true;
    options.deadAssignmentElimination = true;
    options.extractPrototypeMemberDeclarations = true;
    options.collapseVariableDeclarations = true;
    options.convertToDottedProperties = true;
    options.rewriteFunctionExpressions = true;
    options.labelRenaming = true;
    options.removeDeadCode = true;
    options.optimizeArgumentsArray = true;
    options.collapseObjectLiterals = true;
    options.protectHiddenSideEffects = true;
    
    // All the advance optimizations.
    options.removeClosureAsserts = true;
    options.aliasKeywords = true;
    options.reserveRawExports = true;
    options.setRenamingPolicy(
        VariableRenamingPolicy.ALL, PropertyRenamingPolicy.ALL_UNQUOTED);
    options.shadowVariables = true;
    options.removeUnusedPrototypeProperties = true;
    options.removeUnusedPrototypePropertiesInExterns = true;
    options.collapseAnonymousFunctions = true;
    options.collapseProperties = true;
    options.checkGlobalThisLevel = CheckLevel.WARNING;
    options.rewriteFunctionExpressions = true;
    options.smartNameRemoval = true;
    options.inlineConstantVars = true;
    options.setInlineFunctions(Reach.ALL);
    options.inlineGetters = true;
    options.setInlineVariables(Reach.ALL);
    options.flowSensitiveInlineVariables = true;
    options.computeFunctionSideEffects = true;
    
    // Remove unused vars also removes unused functions.
    options.setRemoveUnusedVariables(Reach.ALL);
    
    // Move code around based on the defined modules.
    options.crossModuleCodeMotion = true;
    options.crossModuleMethodMotion = true;
    
    // Call optimizations
    options.devirtualizePrototypeMethods = true;
    options.optimizeParameters = true;
    options.optimizeReturns = true;
    options.optimizeCalls = true;
    

    Technically, SIMPLE_OPTIMIZATIONS would give you argument renaming., in case advanced start causing problems with your code (again from the source):

    /**
     * SIMPLE_OPTIMIZATIONS performs transformations to the input JS that do not
     * require any changes to JS that depend on the input JS. For example,
     * function arguments are renamed (which should not matter to code that
     * depends on the input JS), but functions themselves are not renamed (which
     * would otherwise require external code to change to use the renamed function
     * names).
     */
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to use the google closure compiler on the javascript source we're using.
I want to use some Jython code as a Groovy closure so I believe
I want to use Google Closure Compiler(GCC further) for joining my js-files and compressing
I want use groovy findAll with my param to filtering closure filterClosure = {
I want use this 1 for using Bar code or QR code scanner. I
Any ideas on how to use Google Closure Compiler to combine multiple JavaScript files
I wanna use Google Closure Compiler to compile my js codes.I write a makefile
I'm using JsDoc3 and the Closure Compiler . I use a JsDoc template which
I want to use goog.addSingletonGetter() ( http://closure-library.googlecode.com/svn/!svn/bc/4/trunk/closure/goog/docs/closure_goog_testing_singleton.js.source.html#line56 ) to add a getInstance() method to
I am trying to make externs for the Google Closure Compiler for types that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.