Home  >  Article  >  Web Front-end  >  js 加密压缩出现bug解决方案_基础知识

js 加密压缩出现bug解决方案_基础知识

WBOY
WBOYOriginal
2016-05-16 16:30:311215browse

这种情况精简后查错的方法:打开IE的脚本错误提示,然后打开调用JS的HTML页面,它会报告缺少分号的所在位置,然后用UE打开精简后JS文件,转到相应位置加上分号,再找到未精简的JS代码中对应的位置加上分号。
例如:

复制代码 代码如下:

var a=1
var b=2

改为:

复制代码 代码如下:

var a=1;
var b=2;

◆尽量在else后面的语句使用大括号
这种情况查错起来比较麻烦,通过正则表达式 else[a-zA-Z0-9]+ 来查找精简后的JS文件,或者查找else后面是否有注释的行,再找到未精简的JS代码中对应的位置加上大括号。
例如:

复制代码 代码如下:

if (a>b)
a=b;
else
b=a;

改为:

复制代码 代码如下:

if (a>b)
a=b;
else
{b=a}

◆尽量在function的反大括号后都加上分号
例如:

复制代码 代码如下:

function a() {
}
function b() {
}

改为:

复制代码 代码如下:

function a() {
};
function b() {
};

这样压缩后才能解决压缩后报错的问题。
同时注意中文乱码的问题,可以不另存为文件而采用复制粘贴的方式。

window.load = function()
{

}
这样定义的,结尾一定要有分号。

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn