對於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>
然後,我創建一個批處理文件與此:
Script WSFFileNameYouUsed.wsf
pause