javascript瘦身,压缩js文件
1、移除换行符与制表符
2、压缩空格
3、替换注释/*内容*/
4、替换下列内容
"{ "替换为"{"
" }"替换为"}"
" ("替换为")"
") "替换为")"
", "替换为","
" ; "替换为";"
Recipe: Compressing/decompressing JavaScript
$ cat sample.js
function sign_out()
{
$("#loading").show();
$.get("log_in",{logout:"True"},
function(){
window.location="";
});
}
Compressing javascript
======================
$ cat sample.js | \
tr -d '\n\t' | tr -s ' ' \
| sed 's:/\*.*\*/::g' \
| sed 's/ \?\([{}();,:]\) \?/\1/g'
function sign_out(){$("#loading").show();$.get("log_in",{logout:"True"},function(){window.location="";});}
解压缩
用";\n"替换";"
用"{\n"替换"{","\n}"替换"}"
$ cat obfuscated.txt | sed 's/;/;\n/g; s/{/{\n\n/g; s/}/\n\n}/g'
or
$ cat obfuscated.txt | sed 's/;/;\n/g' | sed 's/{/{\n\n/g' | sed 's/}/\n\n}/g'
$ cat obfuscated.txt | sed 's/;/;\n/g; s/{/{\n\n/g; s/}/\n\n}/g'
function sign_out(){
$("#loading").show();
$.get("log_in",{
logout:"True"
},function(){
window.location="";
});