Preserve custom blocks with YUI Compressor
I am using YUI Compressor to minify Javascript files. Howe开发者_运维技巧ver these Javascript files contains some custom content (embedded JSP tags) that I would need YUI Compressor to ignore. I am looking for something similar to the "custom preservation rules" in htmlcompressor.
Does anyone know whether this can be done with YUI Compressor? If not, can anyone suggest an alternative?
From the YUI compressor docs, you might be able to do this using "hints":
+ It is possible to prevent a local variable, nested function or function
argument from being obfuscated by using "hints". A hint is a string that
is located at the very beginning of a function body like so:
function fn (arg1, arg2, arg3) {
"arg2:nomunge, localVar:nomunge, nestedFn:nomunge";
...
var localVar;
...
function nestedFn () {
....
}
...
}
In your case, you could add a nested function and use the "nomunge" hint for that function.
If you're using JSP to generate javascript, then compress the output of the JSP script, rather than before.
If you can't, you should split off the javascript that is static, and serve the dynamic javascript separately.
精彩评论