I'm using Google's Closure compiler to shrink my JS. There are several places in my code where I have a repeated string, e.g.
(function($){
$('.bat').append('<p>the red car has a fantastically wonderfully awe inspiringly world class engine</p><p>the blue car has a fantastically wonderfully awe inspiringly world class stereo</p><p>the green car has a fantastically wonderfully awe inspiringly world class horn</p>')
})(jQuery);
The compiler wasn't minimizing that redundancy (to be expected) so I did it myself in the 'precompiled' code:
(function($){
var ch = ' car has a fantastically wonderfully awe inspiringly world class ';
$('.bat').append('<p>the red'+ch+'engine</p><p>the blue'+ch+'stereo</p><p>the green'+ch+'horn</p>')
})(jQuery);
But when I run that through the compiler it reverses my compression, which results in more characters. It outputs:
(function(a){a(".bat").append("<p>the red car has a fantastically wonderfully awe inspiringly world class engine</p><p>the blue car has a fantastically wonderfully awe inspiringly world class stereo</p><p>the green car has a fantastically wonderfully awe inspiringly world class horn</p>")})(jQuery);
Is there a way to prevent this? Any idea why it's being done? Is it a run-time performance improvement?
thanks
chis not used outside, and it saves bytes (and improves performance) by inlining it. Your way of doing it does not seem to be any sort of solution for avoiding "repeated strings". Also, beware that although repeated strings look to be inefficient in storage, they do not affect gzipped size.