13

I'm in the middle of writing a jQuery plugin, and I'd like to shrink the size of my script by replacing commonly used CSS property strings with enums. However, Google's Closure Compiler replaces all string variables with string literals. For example, with advanced optimization selected:

this

var x = "hey bob how are you doing";
alert(x);
alert(x);
alert(x);
alert(x);

returns

alert("hey bob how are you doing");alert("hey bob how are you doing");alert("hey bob how are you doing");alert("hey bob how are you doing");

What is the right way to do what I'm trying to do without sending my code through a string compressor like JScrambler?

Thanks in advance.

2
  • 15
    The expanded version reduces gzipped-size. The compiler is doing the right thing to minimize the gzipped download size and to speed up the script by eliminating a variable. There is an aliasAllStrings flag that will force aliasing of strings -- essentially creating one variable for each string. Commented Jul 30, 2011 at 5:20
  • Ah, that makes perfect sense. Thanks! Commented Jul 30, 2011 at 17:53

1 Answer 1

4

Stephen Chung's answer ( so this question can show as answered ):

The expanded version reduces gzipped-size. The compiler is doing the right thing to minimize the gzipped download size and to speed up the script by eliminating a variable. There is an aliasAllStrings flag that will force aliasing of strings -- essentially creating one variable for each string.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.