当前位置:首页 » 文件管理 » js压缩工具

js压缩工具

发布时间: 2022-01-08 19:51:58

❶ 打开JS是压缩的,怎么解压

网络搜索:"js格式化工具"
http://tool.oschina.net/codeformat/js/ 这个网址是在线格式化的可以试试

javascript代码压缩用压缩工具还是自己写代码压缩

一般用工具,可以使用ant做些自动化压缩设置,
推荐两个:
1.yui compressor
http://www.oschina.net/p/yui+compressor
2.Google Closure Compiler

❸ js代码压缩!

http://tools.css-js.com/compressor.html
这个站点里面有四个压缩引擎,一个YUI压缩,一个UglifyJS压缩,一个JSPacker压缩,和一个新的JsMin压缩。
一般用UglifyJS引擎压缩就可以。jQuery和好些其他的前端项目就是用他压缩的。

另外给个建议,你把你的JS文件用匿名函数的方式封装起来,对外只给一个接口。这样JS压缩引擎就可以把你匿名函数中不对外开放的内部变量名称都给替换成a,b,c,d这样的单字符,很能节省体积。

❹ 怎样将js 压缩成 jsgz 文件

html中内嵌js代码修改为外部调用的方法: 1,新建一个js文件,将html中之前的代码全部选中剪切到该js文件中。如下这个案例,就只剪切其中的alert("测试")。 alert("测试");2,在html中添加js文件调用代码

❺ HTML/CSS/JS 压缩工具

网络直接搜索,比如JS解压或压缩。只有网页版的 别的工具我还真不知道,如果哪个大侠有的话 也给我个邮箱 [email protected]

❻ 哪位有js代码压缩工具,跪求,好用追加

不必那么麻烦,网络“js代码压缩”,有现成的工具,JQuery官方,和一些第三方的都有,你把代码粘贴上,选择你要的设置,就可以完成压缩。

❼ 谁有JavaScript压缩工具 好用的 给我一份

给你我自己用的代码吧~~~
package com.wanghe;
import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;

/**
* 脚本处理类
* 1.实现压缩单个js文件--去除注释换行和多个空格,最终输出一行字符串
* 2.实现批量js压缩功能,压缩目录下的所有js文件到对应的输出目录下
* 3.实现js合并功能 根据需要压缩的列表和输出文件路径及是否压缩生成对应文件
* @author zheng
* @version 1.0
*/
public class ScriptHelp
{
private static final String ENCODE = "GBK";

public static void main(String[] args)
{
//批量压缩js文件
String baseScriptPath = "D:/easy-tab.js";
String miniScriptPath = "D:/mini/easy-tab-mini.js";
//batchCompressJS(baseScriptPath,miniScriptPath);
compressSingleJS(baseScriptPath,miniScriptPath);
//压缩单个js文件
//compressSingleJS("D:/workspace/coos/WebRoot/scripts/coos.js","D:/workspace/coos/WebRoot/scripts/mini/coos.js");
/*
//合并js文件
List<String> fileList = new ArrayList<String>();
fileList.add("D:/workspace/coos/WebRoot/scripts/coos.js");
fileList.add("D:/workspace/coos/WebRoot/scripts/coos.extend.ajax.js");
String toFile = "D:/workspace/coos/WebRoot/scripts/mini/coos.js";
mergeJS(fileList,toFile,true);
*/
}
/**
* 批量压缩js,压缩当前目录下的所有js
* @param baseScriptPath 要压缩的文件目录
* @param miniScriptPath 输出压缩后对应的目录
*/
@SuppressWarnings("unchecked")
public static void batchCompressJS(String baseScriptPath,String miniScriptPath)
{
//获取当前目录下所以js文件路径(不包括子目录)
List fileList = getListFiles(baseScriptPath,"js",false);

for (Iterator i = fileList.iterator(); i.hasNext();)
{
String fromFile = (String) i.next();
String toFile = miniScriptPath +fromFile.substring(fromFile.lastIndexOf("/"), fromFile.length());
compressSingleJS(fromFile,toFile);
}
}

/**
* 压缩单个js文件
* @param fromFile
* @param toFile
*/
public static void compressSingleJS(String fromFile,String toFile)
{
String content = readFile(fromFile);
writeFile(compressJS(content),toFile);
}
/**
* 合并js文件
* @param fileList 文件全路径的list,需要按顺序
* @param toFile 输出文件的全路径
* @param isCompress 是否压缩
*
*/
@SuppressWarnings("unchecked")
public static void mergeJS(List fileList,String toFile,Boolean isCompress)
{
String content = "";
for (Iterator i = fileList.iterator(); i.hasNext();)
{
String fromFile = (String) i.next();
content += readFile(fromFile);
}
if(isCompress == true)
writeFile(compressJS(content),toFile);
else
writeFile(content,toFile);
}
/**
* 去除注释、多个空格和换行,最终形成一行的字符串
* @param content 要压缩的内容
* @return 压缩后的内容
*/
public static String compressJS(String content)
{
//去掉/*some code*/的注释 注意alert()里不要有/**/
content = content.replaceAll("//.*[\\r\\n]","");
//去掉/*some code*/的注释 注意alert()里不要有/**/
content = content.replaceAll("\\/\\*(a|[^a])*?\\*\\/","");
/*多余的空格*/
content = content.replaceAll("\\s{2,}"," ");
//等号两边的空格去掉
content = content.replaceAll("\\s*=\\s*","=");
//}两边的空格去掉
content = content.replaceAll("\\s*}\\s*","}");
//{两边的空格去掉
content = content.replaceAll("\\s*\\{\\s*","\\{");
//冒号两边的空格去掉
content = content.replaceAll("\\s*:\\s*",":");
//逗号两边的空格去掉
content = content.replaceAll("\\s*,\\s*",",");
//分号两边的空格去掉
content = content.replaceAll("\\s*;\\s*",";");
//与两边的空格去掉
content = content.replaceAll("\\s*&&\\s*","&&");
//或两边的空格去掉
content = content.replaceAll("\\s*\\|\\|\\s*","\\|\\|");
/*替换换行和回车*/
content = content.replaceAll("\\r\\n","").replaceAll("\\n", "");
return content;
}
/**
* 输出文件,编码为UTF-8 用记事本另存为:fileContent 全部为英文则为ansi 包含中文则为UTF-8
* @param content 要输出的文件内容
* @param comspec 全路径名
*/
public static void writeFile(String content,String comspec)
{
try
{
int i = comspec.lastIndexOf("/");
String dirs = comspec.substring(0,i);
File file = new File(dirs);
if(!file.exists()){
file.mkdir();
}
file = new File(comspec);
if(!file.exists()){
file.createNewFile();
}
FileOutputStream fos = new FileOutputStream(file);
Writer out = new OutputStreamWriter(fos,ENCODE);
out.write(content);
System.out.println("成功输出文件:" + comspec);
out.close();
fos.close();
} catch (IOException e)
{
System.out.println("写文件操作出错!");
e.printStackTrace();
}
}

/**
* 读取文件内容
* @param filePath
* @return String
*/
public static String readFile(String filePath)
{
StringBuilder sb = new StringBuilder();
try
{
File file = new File(filePath);
InputStreamReader read = new InputStreamReader (new FileInputStream(file),ENCODE);
BufferedReader reader=new BufferedReader(read);
String s = reader.readLine();
while (s != null)
{
sb.append(s);
sb.append("\r\n");
s = reader.readLine();
}
reader.close();
} catch (IOException e)
{
e.printStackTrace();
}
return sb.toString();
}

public static List<String> fileList = new ArrayList<String>();
/**
* @param path 文件路径
* @param suffix 后缀名
* @param isdepth 是否遍历子目录
* @return fileList
*/
@SuppressWarnings("unchecked")
public static List getListFiles(String path, String suffix, boolean isdepth)
{
File file = new File(path);
return listFile(path,file ,suffix, isdepth);
}
/**
* 获取当前目录下文件路径
* @param path
* @param f
* @param suffix
* @param isdepth
* @return
*/
@SuppressWarnings("unchecked")
public static List listFile(String path, File f, String suffix, boolean isdepth)
{
//是目录,同时需要遍历子目录
String temp = path.replaceAll("/","\\\\");
if ((f.isDirectory() && isdepth == true) || temp.equals(f.getAbsolutePath()))
{
File[] t = f.listFiles();
for (int i = 0; i < t.length; i++)
{
listFile(path,t[i], suffix, isdepth);
}
}
else
{
addFilePath(f ,suffix, isdepth);
}
return fileList;
}

/**
* 添加文件路径到list中
* @param f
* @param suffix
* @param isdepth
* @return
*/
@SuppressWarnings("unchecked")
public static List addFilePath(File f, String suffix, boolean isdepth)
{
String filePath = f.getAbsolutePath().replaceAll("\\\\", "/");
if(suffix !=null)
{
int begIndex = filePath.lastIndexOf(".");
String tempsuffix = "";

if(begIndex != -1)//防止是文件但却没有后缀名结束的文件
{
tempsuffix = filePath.substring(begIndex + 1, filePath.length());
}
if(tempsuffix.equals(suffix))
{
fileList.add(filePath);
}
}
else
{
fileList.add(filePath);//后缀名为null则为所有文件
}
return fileList;
}

}

❽ 能不能推荐一下CSS的压缩软件和js的压缩软件

YUI Compressor 是一个用来压缩 JS 和 CSS 文件的工具,采用Java开发。使用方法://压缩JSjava -jar yuicompressor-2.4.2.jar --type js --charset utf-8 -v src.js > packed.js//压缩CSSjava -jar yuicompressor-2.4.2.jar --type css --charset utf-8 -v src.css > packed.css下载地址 http://www.julienlecomte.net/yuicompressor/yuicompressor-2.4.2.zip

❾ 网站发布的时候批量混淆,压缩JS代码用什么工具

此代码纯属装B用,就是js的各种类型间转换,记住js的数据类型(这里用到的):[ObjectObject]falsetrueundefined然后把他们转成string,通过数组下标取值,在字符串拼接就成了!如:!![]+[];//true+[];//0组合:(!![]+[])(+[]);//就是‘t'

❿ 如何压缩js

简单的压缩一般是:删除注释和空白符,替换变量名。

更激进点的做法还包括:删除无用代码,内联函数,等价语句替换等。

有些开发者出于保护代码的原因,还可能会对代码进行混淆处理。

通常深度压缩JS都必须要做的一步就是尽量地缩短变量名,因为一份体积巨大的JS代码,其中的变量名会占去不少空间。

压缩js必须要注意:

1、压缩前的代码格式要标准。因为去掉换行与空格时,所有语句就变成一行,如果你的代码有瑕疵(比如某行少了个分号),那就会导致整个文件报错。当然,现在有的压缩工具已经比较智能了。

2、备份原文件。压缩很可能不会一次成功,一般要多试,多改。

js压缩工具:

1. YUI Compressor

2. Google Closure Compiler

热点内容
安卓手机连拍限制张数怎么办 发布:2024-05-20 16:13:07 浏览:288
数据库精品课程网站 发布:2024-05-20 15:56:06 浏览:354
常用的外部存储器包括 发布:2024-05-20 15:43:19 浏览:661
有什么软件可以修改wife密码 发布:2024-05-20 15:41:51 浏览:649
c语言矩阵求逆 发布:2024-05-20 15:38:09 浏览:48
易通文件夹 发布:2024-05-20 15:36:25 浏览:996
斗罗大陆斗罗武魂是什么服务器 发布:2024-05-20 15:33:38 浏览:715
亚马逊的苹果和安卓哪个好 发布:2024-05-20 15:32:57 浏览:549
彩虹岛空中战场什么配置 发布:2024-05-20 15:23:31 浏览:525
c语言如何把字符串赋给字符数组 发布:2024-05-20 15:23:28 浏览:784