Reputation: 327
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.
Upvotes: 13
Views: 792
Reputation: 5911
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.
Upvotes: 4