WebOptimizer
WebOptimizer copied to clipboard
Wrong js concatenating after minification in some cases
If we have setup like
//Concatenate all to one file and minify this file
pipeline.AddBundle(path, contentType, files)
.EnforceFileExtensions(".js")
.Concatenate()
.MinifyJavaScript()
and if some files are already minified, we will minify them one more time. It's wrong.
If we change sutup like
//Minify all non minified files and then concatenate .min to one file
pipeline.AddBundle(path, contentType, files)
.EnforceFileExtensions(".js")
.MinifyJavaScript()
.Concatenate()
to minify all except already minified, then it's possible when
- one js file ends with anonymous immediately invoked function
- and next file starts with anonymous immediately invoked function
we need to add separator ';' to avoid wrong syntax like
(function(){})()(function(){})()
when correct syntaxt is (function(){})();(function(){})();
I guess the best solution is to add separator as parameter in .Concatenate() to have setup like
pipeline.AddBundle(path, contentType, files)
.EnforceFileExtensions(".js")
.MinifyJavaScript()
.Concatenate(";") //with custom separator
Or add this separator as default between js files