对于 JS,我一直很喜欢这个脚本:
http://jsutility.pjoneil.net
我有多个 JS 文件,将其作为批处理脚本运行,它将所有文件组合到一个文件中,对它们进行模糊处理,压缩它们,然后压缩它们。它工作得很好。我有超过 2mb 的 javascript 压缩到大约 350kb 使用这个加上它的免费!
快速示例,从网站下载代码,然后大致创建一个 wsf 文件。
<job id="ObfuscateJavascript">
<script language="VBScript">
Function WSHInputBox(Message, Title, Value)
WSHInputBox = InputBox(Message, Title, Value)
End Function
</script>
<reference object="Scripting.FileSystemObject" />
<script language="JScript" src="JSUtility_BatchCodeC.js" />
<script language="JScript">
var vbOKOnly = 0;
var vbInformation = 64;
var title = "What Project are you building for?";
var prompt = "Enter a file name:";
var WshShell = WScript.CreateObject("WScript.Shell");
var result = WSHInputBox(prompt, title, "FileName");
if (typeof result != "undefined") {
InputFiles.push("File1.js");
InputFiles.push("File2.js");
InputFiles.push("File3.js");
// Obfuscation options
Obfuscate.Options = {
DefinedGlobalVars: true,
ObjectMembers: false,
StringVariables: true,
MinimumStringLength: 12,
RestructureIfStmts: true
};
// Compaction options
Compact.Options = {
AddMissingSemicolons: true,
LeaveNewLines: false,
LeaveNewLineAndComment: false,
RemoveUnnecessarySemicolons: true
};
// Compression options
Compress.Options = {
ISO8859Compatable: true,
UTF8Compatible: true
};
// File output
OutputFile = result + ".min.js";
// Operations to apply to javascript
Operations = {
Validate: false,
Obfuscate: true,
Compact: true,
Compress: true,
StopOnWarning: false
};
JSUtilityBatch();
}
</script>
</job>
然后我用这个创建一个 bat 文件:
Script WSFFileNameYouUsed.wsf
pause