當前位置:首頁 » 文件管理 » 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

熱點內容
sql資料庫安全 發布:2024-09-20 08:31:32 瀏覽:87
蘋果連接id伺服器出錯是怎麼回事 發布:2024-09-20 08:01:07 瀏覽:502
編程鍵是什麼 發布:2024-09-20 07:52:47 瀏覽:651
學考密碼重置要求的證件是什麼 發布:2024-09-20 07:19:46 瀏覽:477
電腦主伺服器怎麼開機 發布:2024-09-20 07:19:07 瀏覽:728
2022款瑞虎升級哪些配置 發布:2024-09-20 06:59:07 瀏覽:265
資料庫與asp 發布:2024-09-20 06:55:25 瀏覽:727
python解釋編譯 發布:2024-09-20 06:52:57 瀏覽:648
舞蹈豐收腳本 發布:2024-09-20 06:36:26 瀏覽:595
linux進程埠號 發布:2024-09-20 06:36:11 瀏覽:80