<HEAD>
<TITLE>Decision Helper</TITLE>
<META http-equiv=Content-Type content="text/htmlcharset=gb2312">
<SCRIPT LANGUAGE="JavaScript">
<!--
function Compress(strNormalString)
{
alert("压缩前长度:" + strNormalString.length)
var strCompressedString = ""
var ht = new HashTable
for(i = 0i <128i++) {
var e = new HashTableElement
e.key = i
e.code = i
ht.Insert(e)
}
var used = 128
var intLeftOver = 0
var intOutputCode = 0
var pcode = 0
var ccode = 0
var k = 0
for(var i=0i<strNormalString.lengthi++) {
ccode = strNormalString.charCodeAt(i)
k = (pcode <<8) | ccode
if((intSearch = ht.Search(k)) != null) {
pcode = intSearch
} else {
intLeftOver += 12
intOutputCode <<= 12
intOutputCode |= pcode
pcode = ccode
if(intLeftOver >= 16) {
strCompressedString += String.fromCharCode( intOutputCode >>( intLeftOver - 16 ) )
intOutputCode &= (Math.pow(2,(intLeftOver - 16)) - 1)
intLeftOver -= 16
}
if(used <4096) {
used ++
var e = new HashTableElement
e.key = k
e.code = used - 1
ht.Insert(e)
}
}
}
if(pcode != 0) {
intLeftOver += 12
intOutputCode <<= 12
intOutputCode |= pcode
}
if(intLeftOver >= 16) {
strCompressedString += String.fromCharCode( intOutputCode >>( intLeftOver - 16 ) )
intOutputCode &= (Math.pow(2,(intLeftOver - 16)) - 1)
intLeftOver -= 16
}
if( intLeftOver >0) {
intOutputCode <<= (16 - intLeftOver)
strCompressedString += String.fromCharCode( intOutputCode )
}
alert("压缩后长度:" + strCompressedString.length)
return strCompressedString
}
function Decompress(strCompressedString)
{
var strNormalString = ""
var ht = new Array
for(i = 0i <128i++)
{
ht[i] = String.fromCharCode(i)
}
var used = 128
var intLeftOver = 0
var intOutputCode = 0
var ccode = 0
var pcode = 0
var key = 0
for(var i=0i<strCompressedString.lengthi++) {
intLeftOver += 16
intOutputCode <<= 16
intOutputCode |= strCompressedString.charCodeAt(i)
在任意文件夹下按住shift按键的同时,点击鼠标右键 打开powershell命令窗口 执行命令: npm install uglify-js -g 首先,打开cmd 其次,查找要压缩的js文件,查找方法如下: 1、输入文件所在位置 例如,我需要压缩的文件在E盘中,就输入 e: 2、输入:cd + js文件所在位置 例如,我需要压缩的js文件在:E:\electron-vue\topology\static\new_node_modules\topology-vue 就执行:cd electron-vue\topology\static\new_node_modules\topology-vue 3、输入:uglifyjs + 要压缩的js文件名称 + -o + 压缩后js文件名称 例如,我要将topology-vue.umd.js文件压缩成topology-vue.umd.min.js 就执行:uglifyjs topology-vue.umd.js -o topology-vue.umd.min.js 你没看错! 就是这么简单!! 将JS文件进行压缩,让你的程序快马加鞭地跑起来吧!!!四、如何生成Source map最常用的方法是使用Google的Closure编译器。
生成命令的格式如下:
java -jar compiler.jar \
--js script.js \
--create_source_map ./script-min.js.map \
--source_map_format=V3 \
--js_output_file script-min.js