看文章名是不是有点绕口啊,其实就是可以用来压缩javascript代码的javascript函数
能不能没测试过,网上找到,大家自己测式吧,
以下为引用的内容: /** * 压缩javascript * @param JS源文件路径(e:/jquery-1.7.1.js) * @param 压缩级别 * @return */ public Compiler miniJS(String sourceJSFile, String comLevel){ String[] primaryJavascriptToCompile = {sourceJSFile}; Compiler.setLoggingLevel(Level.OFF); Compiler compiler = new Compiler(); //设置压缩级别 CompilerOptions options = new CompilerOptions(); if(comLevel.equals("0")){ CompilationLevel.WHITESPACE_ONLY.setOptionsForCompilationLevel(options); }else if(comLevel.equals("1")){ CompilationLevel.SIMPLE_OPTIMIZATIONS.setOptionsForCompilationLevel(options); }else{ CompilationLevel.ADVANCED_OPTIMIZATIONS.setOptionsForCompilationLevel(options); } //警告级别 WarningLevel.DEFAULT.setOptionsForWarningLevel(options); List<JSSourceFile> externalJavascriptFiles = new ArrayList<JSSourceFile>(); List<JSSourceFile> primaryJavascriptFiles = new ArrayList<JSSourceFile>(); for(String filename : primaryJavascriptToCompile){ primaryJavascriptFiles.add(JSSourceFile.fromFile(filename)); } compiler.compile(externalJavascriptFiles, primaryJavascriptFiles, options); return compiler; } |